From 7a0d2aaed53dc0500860691320a90bc1e695b795 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Tue, 26 Jan 2021 15:28:37 +0000 Subject: [PATCH 001/454] - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 91bc0f3..378058e 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.21 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -361,6 +361,9 @@ done %endif %changelog +* Tue Jan 26 2021 Fedora Release Engineering - 2.0.21-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild + * Fri Jan 22 2021 Kairui Song - 2.0.21-4 - dracut-module-setup.sh: enable ForwardToConsole=yes in fadump mode - kdump.conf: add ipv6 example for nfs and ssh dump From 18131894b609eb233496af81d034d65c96d4d0e6 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Thu, 4 Feb 2021 09:45:36 +0800 Subject: [PATCH 002/454] kdump-lib.sh: introduce functions to return recommened mem size There is requirement to decide the recommended memory size for the current system. And the algorithm is based on /proc/iomem, so it can align with the algorithm used by reserve_crashkernel() in kernel. Signed-off-by: Pingfan Liu Acked-by: Kairui Song --- kdump-lib.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index d2801da..46e5e03 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -823,3 +823,71 @@ prepare_cmdline() echo ${cmdline} } + +#get system memory size in the unit of GB +get_system_size() +{ + result=$(cat /proc/iomem | grep "System RAM" | awk -F ":" '{ print $1 }' | tr [:lower:] [:upper:] | paste -sd+) + result="+$result" + # replace '-' with '+0x' and '+' with '-0x' + sum=$( echo $result | sed -e 's/-/K0x/g' | sed -e 's/+/-0x/g' | sed -e 's/K/+/g' ) + size=$(printf "%d\n" $(($sum))) + let size=$size/1024/1024/1024 + + echo $size +} + +get_recommend_size() +{ + local mem_size=$1 + local _ck_cmdline=$2 + local OLDIFS="$IFS" + + last_sz="" + last_unit="" + + IFS=',' + for i in $_ck_cmdline; do + end=$(echo $i | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $1 }') + recommend=$(echo $i | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $2 }') + size=${end: : -1} + unit=${end: -1} + if [ $unit == 'T' ]; then + let size=$size*1024 + fi + if [ $mem_size -lt $size ]; then + echo $recommend + IFS="$OLDIFS" + return + fi + done + IFS="$OLDIFS" +} + +# return recommended size based on current system RAM size +kdump_get_arch_recommend_size() +{ + if ! [[ -r "/proc/iomem" ]] ; then + echo "Error, can not access /proc/iomem." + return 1 + fi + arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr [:lower:] [:upper:]) + + if [ $arch == "X86_64" ] || [ $arch == "S390" ]; then + ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" + elif [ $arch == "ARM64" ]; then + ck_cmdline="2G-:448M" + elif [ $arch == "PPC64LE" ]; then + if is_fadump_capable; then + ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" + else + ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" + fi + fi + + ck_cmdline=$(echo $ck_cmdline | sed -e 's/-:/-102400T:/g') + sys_mem=$(get_system_size) + result=$(get_recommend_size $sys_mem "$ck_cmdline") + echo $result + return 0 +} From f39000f5240e577347d2cdae8fd9bcb710fe7325 Mon Sep 17 00:00:00 2001 From: "fj1508ic@fujitsu.com" Date: Tue, 26 Jan 2021 06:37:28 +0000 Subject: [PATCH 003/454] Remove trace_buf_size and trace_event from the kernel bootparameters of the kdump kernel The kdump kernel uses resources for ftrace because trace_buf_size, which specifies the ring buffer size for ftrace, and trace_event, which specifies a valid trace event, are not removed, but the kdump kernel does not require ftrace. trace_buf_size is ignored if the specified size is 0, so specify 1. Signed-off-by: Hisashi Nagaoka Acked-by: Kairui Song --- kdump-lib.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 46e5e03..537d5f8 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -821,6 +821,10 @@ prepare_cmdline() fi done + # Remove trace_buf_size, trace_event + cmdline=$(remove_cmdline_param "$cmdline" trace_buf_size trace_event) + cmdline="${cmdline} trace_buf_size=1" + echo ${cmdline} } From 7232f5bff204d4271c02bfd421aef2e8974bd888 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 8 Feb 2021 23:21:25 +0800 Subject: [PATCH 004/454] Release 2.0.21-6 Signed-off-by: Kairui Song --- kexec-tools.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 378058e..30266da 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.21 -Release: 5%{?dist} +Release: 6%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -361,6 +361,10 @@ done %endif %changelog +* Mon Feb 08 2021 Kairui Song - 2.0.21-6 +- Remove trace_buf_size and trace_event from the kernel bootparameters of the kdump kernel +- kdump-lib.sh: introduce functions to return recommened mem size + * Tue Jan 26 2021 Fedora Release Engineering - 2.0.21-5 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild From 2721f323a9fb105471727de3093dda459326aba4 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 8 Feb 2021 14:13:54 +0800 Subject: [PATCH 005/454] add dependency on ipcalc ipcalc is needed for generating 45route-static.conf. However, on newer Fedora, e.g. 34, dracut-network drops dependency on dhcp-client which requires ipcalc. Make kexec-tools explicitly depends on ipcalc. Reported-by: Jie Li Signed-off-by: Coiby Xu Acked-by: Kairui Song --- kexec-tools.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/kexec-tools.spec b/kexec-tools.spec index 30266da..3cbecb5 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -63,6 +63,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Recommends: dracut-squash >= 050 Requires: ethtool +Requires: ipcalc BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext From 596fa0a07f089a9dd54cf631124d88653b4d77ec Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Thu, 18 Feb 2021 14:01:18 +0800 Subject: [PATCH 006/454] kdumpctl: enable secure boot on ppc64le LPARs On ppc64le LPAR, secure-boot is a little different from bare metal, Where host secure boot: /ibm,secure-boot/os-secureboot-enforcing DT property exists while guest secure boot: /ibm,secure-boot >= 2 Make kexec-tools adapt to LPAR Signed-off-by: Pingfan Liu Acked-by: Kairui Song --- kdump-lib.sh | 9 +++++++-- kdumpctl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 537d5f8..21271cf 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -621,11 +621,16 @@ is_secure_boot_enforced() local secure_boot_file setup_mode_file local secure_boot_byte setup_mode_byte - # On powerpc, os-secureboot-enforcing DT property indicates whether secureboot - # is enforced. Return success, if it is found. + # On powerpc, secure boot is enforced if: + # host secure boot: /ibm,secure-boot/os-secureboot-enforcing DT property exists + # guest secure boot: /ibm,secure-boot >= 2 if [ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]; then return 0 fi + if [ -f /proc/device-tree/ibm,secure-boot ] && \ + [ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]; then + return 0 + fi # Detect secure boot on x86 and arm64 secure_boot_file=$(find /sys/firmware/efi/efivars -name SecureBoot-* 2>/dev/null) diff --git a/kdumpctl b/kdumpctl index 24f5cf7..c3311ad 100755 --- a/kdumpctl +++ b/kdumpctl @@ -638,6 +638,35 @@ check_rebuild() return $? } +# On ppc64le LPARs, the keys trusted by firmware do not end up in +# .builtin_trusted_keys. So instead, add the key to the .ima keyring +function load_kdump_kernel_key() +{ + # this is only called inside is_secure_boot_enforced, + # no need to retest + + # this is only required if DT /ibm,secure-boot is a file. + # if it is a dir, we are on OpenPower and don't need this. + if ! [ -f /proc/device-tree/ibm,secure-boot ]; then + return + fi + + KDUMP_KEY_ID=$(cat /usr/share/doc/kernel-keys/$KDUMP_KERNELVER/kernel-signing-ppc.cer | + keyctl padd asymmetric kernelkey-$RANDOM %:.ima) +} + +# remove a previously loaded key. There's no real security implication +# to leaving it around, we choose to do this because it makes it easier +# to be idempotent and so as to reduce the potential for confusion. +function remove_kdump_kernel_key() +{ + if [ -z "$KDUMP_KEY_ID" ]; then + return + fi + + keyctl unlink $KDUMP_KEY_ID %:.ima +} + # Load the kdump kernel specified in /etc/sysconfig/kdump # If none is specified, try to load a kdump kernel with the same version # as the currently running kernel. @@ -654,6 +683,7 @@ load_kdump() if is_secure_boot_enforced; then dinfo "Secure Boot is enabled. Using kexec file based syscall." KEXEC_ARGS="$KEXEC_ARGS -s" + load_kdump_kernel_key fi ddebug "$KEXEC $KEXEC_ARGS $standard_kexec_args --command-line=$KDUMP_COMMANDLINE --initrd=$TARGET_INITRD $KDUMP_KERNEL" @@ -675,6 +705,8 @@ load_kdump() set +x exec 2>&12 12>&- + remove_kdump_kernel_key + if [ $ret == 0 ]; then dinfo "kexec: loaded kdump kernel" return 0 From da6f381b081469fccf12110a398d03d1c0810b3f Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Thu, 18 Feb 2021 14:12:00 +0530 Subject: [PATCH 007/454] fadump: improve fadump-howto.txt about remote dump target setup While fadump-howto.txt talks about what happens to network interface name on setting up a remote dump target in FADump mode, it doesn't explicitly specify the negative consequences of it. Make it explicit and provide a recommendation to overcome the same. Signed-off-by: Hari Bathini Acked-by: Kairui Song --- fadump-howto.txt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fadump-howto.txt b/fadump-howto.txt index 5360f3d..433e9a6 100644 --- a/fadump-howto.txt +++ b/fadump-howto.txt @@ -224,12 +224,16 @@ Things to remember: dracut_args --add "network" 4) If FADump is configured to capture vmcore to a remote dump target using SSH - or NFS protocol, the network interface is renamed to kdump- - if is generic, for example, *eth#, or net#. This problem - occurs because the vmcore capture scripts in the initial RAM disk (initrd) - add the kdump- prefix to the network interface name to secure persistent - naming. As the same initrd is used for production kernel boot, the interface - name is changed for the production kernel too. + or NFS protocol, the corresponding network interface '' is + renamed to 'kdump-', if it is generic (like *eth# or net#). + It happens because vmcore capture scripts in the initial RAM disk (initrd) + add the 'kdump-' prefix to the network interface name to secure persistent + naming. And as capture kernel and production kernel use the same initrd in + case of FADump, the interface name is changed for the production kernel too. + This is likely to impact network configuration setup for production kernel. + So, it is recommended to use a non-generic name for a network interface, + before setting up FADump to capture vmcore to a remote dump target based on + that network interface, to avoid running into network configuration issues. Dump Triggering methods: From 4b7ff283f5efb4c6e007ef56e4dec74c8a4fbd20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 2 Mar 2021 16:13:34 +0100 Subject: [PATCH 008/454] Rebuilt for updated systemd-rpm-macros See https://pagure.io/fesco/issue/2583. --- kexec-tools.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 3cbecb5..00cf64c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.21 -Release: 6%{?dist} +Release: 7%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -362,6 +362,10 @@ done %endif %changelog +* Tue Mar 02 2021 Zbigniew Jędrzejewski-Szmek - 2.0.21-7 +- Rebuilt for updated systemd-rpm-macros + See https://pagure.io/fesco/issue/2583. + * Mon Feb 08 2021 Kairui Song - 2.0.21-6 - Remove trace_buf_size and trace_event from the kernel bootparameters of the kdump kernel - kdump-lib.sh: introduce functions to return recommened mem size From 6a2e820d87106592678391c2cb7befa7033a3cb0 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Sun, 21 Feb 2021 17:23:37 +0530 Subject: [PATCH 009/454] Stop reloading kdump service on CPU hotplug event for FADump As FADump does not require an explicit elfcorehdr update whenever there is CPU hotplug event so let's stop kdump service reload for FADump when CPU hotplug event is triggered. A new label is added to handle CPU and memory hotplug events separately. The updated CPU hotplug event handler make sure that kdump service should not be reloaded when FADump is configured. Signed-off-by: Sourabh Jain Reviewed-by: Pingfan Liu Acked-by: Baoquan He --- 98-kexec.rules.ppc64 | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/98-kexec.rules.ppc64 b/98-kexec.rules.ppc64 index 1a91220..a1c00a9 100644 --- a/98-kexec.rules.ppc64 +++ b/98-kexec.rules.ppc64 @@ -1,15 +1,22 @@ -SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload" -SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload" -SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload" +SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu" +SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload_mem" +SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload_mem" GOTO="kdump_reload_end" -LABEL="kdump_reload" - # If kdump is not loaded, calling kdump-udev-throttle will end up # doing nothing, but systemd-run will always generate extra logs for # each call, so trigger the kdump-udev-throttler only if kdump # service is active to avoid unnecessary logs + +LABEL="kdump_reload_mem" + RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'" +GOTO="kdump_reload_end" + +LABEL="kdump_reload_cpu" + +RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; ! test -f /sys/kernel/fadump_enabled || cat /sys/kernel/fadump_enabled | grep 0 || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'" + LABEL="kdump_reload_end" From 00785873ef364dcbca8765ba22a48a01bdd4fca5 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Fri, 19 Mar 2021 18:07:51 +0800 Subject: [PATCH 010/454] Fix incorrect vmcore permissions when dumped through ssh Previously when dumping vmcore to a remote machine through ssh, the files are created remotely and file permissions are taken from the default umask value, which making the files accessible to anyone on the remote machine. This patch fixed the security issue by setting a customized umask value before the file creation on the remote machine. Signed-off-by: Tao Liu Acked-by: Kairui Song --- dracut-kdump.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 3367bc5..3e65c44 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -136,7 +136,7 @@ dump_ssh() fi _exitcode=$? else - $CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "dd bs=512 of=$_dir/vmcore-incomplete" + $CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "umask 0077 && dd bs=512 of=$_dir/vmcore-incomplete" _exitcode=$? _vmcore="vmcore.flat" fi @@ -218,7 +218,7 @@ save_vmcore_dmesg_ssh() { local _location=$4 dinfo "saving vmcore-dmesg.txt to $_location:$_path" - $_dmesg_collector /proc/vmcore | ssh $_opts $_location "dd of=$_path/vmcore-dmesg-incomplete.txt" + $_dmesg_collector /proc/vmcore | ssh $_opts $_location "umask 0077 && dd of=$_path/vmcore-dmesg-incomplete.txt" _exitcode=$? if [ $_exitcode -eq 0 ]; then From 91c802ff526a0aa0618f6d5c282a9b9b8e41bff8 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 18 Mar 2021 16:52:46 +0800 Subject: [PATCH 011/454] Fix incorrect permissions on kdump dmesg file Also known as CVE-2021-20269. The kdump dmesg log files(kexec-dmesg.log, vmcore-dmesg.txt) are generated by shell redirection, which take the default umask value, making the files readable for group and others. This patch chmod these files, making them only accessible to owner. Signed-off-by: Tao Liu Acked-by: Kairui Song --- dracut-module-setup.sh | 1 + kdump-lib-initramfs.sh | 2 ++ 2 files changed, 3 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 21143b4..8316589 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -849,6 +849,7 @@ install() { inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg" inst "/usr/bin/printf" "/sbin/printf" inst "/usr/bin/logger" "/sbin/logger" + inst "/usr/bin/chmod" "/sbin/chmod" inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh" inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh" inst "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh" diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 86065be..5cb0223 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -111,6 +111,7 @@ save_log() if command -v journalctl > /dev/null; then journalctl -ab >> $KDUMP_LOG_FILE fi + chmod 600 $KDUMP_LOG_FILE } # dump_fs @@ -178,6 +179,7 @@ save_vmcore_dmesg_fs() { _exitcode=$? if [ $_exitcode -eq 0 ]; then mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt + chmod 600 ${_path}/vmcore-dmesg.txt # Make sure file is on disk. There have been instances where later # saving vmcore failed and system rebooted without sync and there From e5a745ce776dd19d617c2025acb3e510585d4e82 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sat, 20 Feb 2021 11:55:52 +0800 Subject: [PATCH 012/454] mkdumprd: prompt the user to install nfs-utils when mounting NFS fs failed When nfs-utils is not installed, mounting as NFS fs would fail. Currently, the error message is not user-friendly, mount: /tmp/mkdumprd.HyPGpS/target: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount. helper program. kdump: Failed to mount on xxx for kdump preflight check. kdump: mkdumprd: failed to make kdump initrd Prompt the user to install nfs-utilsa in the error message, kdump: Failed to mount on xxx for kdump preflight check. Please make sure nfs-utils has been installed. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- mkdumprd | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mkdumprd b/mkdumprd index c34b79c..50ebdc8 100644 --- a/mkdumprd +++ b/mkdumprd @@ -185,6 +185,26 @@ check_save_path_fs() fi } +mount_failure() +{ + local _target=$1 + local _mnt=$2 + local _fstype=$3 + local msg="Failed to mount $_target" + + if [ -n "$_mnt" ]; then + msg="$msg on $_mnt" + fi + + msg="$msg for kdump preflight check." + + if [[ $_fstype = "nfs" ]]; then + msg="$msg Please make sure nfs-utils has been installed." + fi + + perror_exit "$msg" +} + check_user_configured_target() { local _target=$1 _cfg_fs_type=$2 _mounted @@ -210,7 +230,7 @@ check_user_configured_target() if ! is_mounted "$_mnt"; then if [[ $_opt = *",noauto"* ]]; then mount $_mnt - [ $? -ne 0 ] && perror_exit "Failed to mount $_target on $_mnt for kdump preflight check." + [ $? -ne 0 ] && mount_failure "$_target" "$_mnt" "$_fstype" _mounted=$_mnt else perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" @@ -220,7 +240,7 @@ check_user_configured_target() _mnt=$MKDUMPRD_TMPMNT mkdir -p $_mnt mount $_target $_mnt -t $_fstype -o defaults - [ $? -ne 0 ] && perror_exit "Failed to mount $_target for kdump preflight check." + [ $? -ne 0 ] && mount_failure "$_target" "" "$_fstype" _mounted=$_mnt fi From 0dedb2c91a3ae2f377a5b368240a293a4c3bd516 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 24 Mar 2021 11:10:34 +0800 Subject: [PATCH 013/454] selftest: Fix bug of collecting test RPMs from argument Currently, TEST_RPMS would be only using the last RPM. Append each RPM path to TEST_RPMs instead, Signed-off-by: Coiby Xu Acked-by: Kairui Song --- tests/scripts/build-scripts/test-base-image.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/build-scripts/test-base-image.sh b/tests/scripts/build-scripts/test-base-image.sh index 5e2d86a..afe1a97 100755 --- a/tests/scripts/build-scripts/test-base-image.sh +++ b/tests/scripts/build-scripts/test-base-image.sh @@ -6,7 +6,7 @@ for _rpm in $@; do if [[ ! -e $_rpm ]]; then perror_exit "'$_rpm' not found" else - TEST_RPMS=$(realpath "$_rpm") + TEST_RPMS="$TEST_RPMS $(realpath "$_rpm")" fi done From bbc064f9582080124a4acc41f7e33e21c4f18a4f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 24 Mar 2021 11:10:35 +0800 Subject: [PATCH 014/454] selftest: add EXTRA_RPMs so dracut RPMs can be installed onto the image to run the tests dracut will build the PRMs which will be installed onto the image to run the tests. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 71b329b..4e9c55f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -74,7 +74,7 @@ $(TEST_ROOT)/output/test-base-image: $(BUILD_ROOT)/inst-base-image $(KEXEC_TOOLS $(BUILD_ROOT)/inst-base-image \ $(TEST_ROOT)/output/test-base-image \ $(TEST_ROOT)/scripts/build-scripts/test-base-image.sh \ - $(KEXEC_TOOLS_RPM) + $(KEXEC_TOOLS_RPM) $(EXTRA_RPMS) test-run: $(TEST_ROOT)/output/test-base-image ifeq ($(strip $(TEST_CASE)),) From 8619f585387d022fd45b1fa153102f3409d9f144 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 24 Mar 2021 11:10:36 +0800 Subject: [PATCH 015/454] selftest: replace qemu-kvm with one based on dracut's run-qemu Dracut's run-qemu could find which virtualization technology to the user in the order of kvm, kqemu, userspace. Using run-qemu could allow running tests where qemu-kvm doesn't exist. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- tests/scripts/run-qemu | 23 +++++++++++++++++++++++ tests/scripts/test-lib.sh | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 tests/scripts/run-qemu diff --git a/tests/scripts/run-qemu b/tests/scripts/run-qemu new file mode 100755 index 0000000..836387a --- /dev/null +++ b/tests/scripts/run-qemu @@ -0,0 +1,23 @@ +#!/bin/bash +# Check which virtualization technology to use +# We prefer kvm, kqemu, userspace in that order. + +# This script is based on https://github.com/dracutdevs/dracut/blob/master/test/run-qemu + +export PATH=/sbin:/bin:/usr/sbin:/usr/bin + +[[ -x /usr/bin/qemu ]] && BIN=/usr/bin/qemu && ARGS="-cpu max" +$(lsmod | grep -q '^kqemu ') && BIN=/usr/bin/qemu && ARGS="-kernel-kqemu -cpu host" +[[ -c /dev/kvm && -x /usr/bin/kvm ]] && BIN=/usr/bin/kvm && ARGS="-cpu host" +[[ -c /dev/kvm && -x /usr/bin/qemu-kvm ]] && BIN=/usr/bin/qemu-kvm && ARGS="-cpu host" +[[ -c /dev/kvm && -x /usr/libexec/qemu-kvm ]] && BIN=/usr/libexec/qemu-kvm && ARGS="-cpu host" +[[ -x /usr/bin/qemu-system-$(uname -i) ]] && BIN=/usr/bin/qemu-system-$(uname -i) && ARGS="-cpu max" +[[ -c /dev/kvm && -x /usr/bin/qemu-system-$(uname -i) ]] && BIN=/usr/bin/qemu-system-$(uname -i) && ARGS="-enable-kvm -cpu host" + +[[ $BIN ]] || { + echo "Could not find a working KVM or QEMU to test with!" >&2 + echo "Please install kvm or qemu." >&2 + exit 1 +} + +exec $BIN $ARGS "$@" diff --git a/tests/scripts/test-lib.sh b/tests/scripts/test-lib.sh index aff5cd3..f8a2249 100644 --- a/tests/scripts/test-lib.sh +++ b/tests/scripts/test-lib.sh @@ -89,7 +89,7 @@ run_test_sync() { local qemu_cmd=$(get_test_qemu_cmd $1) if [ -n "$qemu_cmd" ]; then - timeout --foreground 10m qemu-kvm $(get_test_qemu_cmd $1) + timeout --foreground 10m $BASEDIR/run-qemu $(get_test_qemu_cmd $1) else echo "error: test qemu command line is not configured" > /dev/stderr return 1 From 91f1d5989b741eea0ec58525e2d784430282ab7a Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 1 Apr 2021 16:53:35 +0800 Subject: [PATCH 016/454] Update eppic to latest upstream snapshot Also fixes a package build failure: ar ccurl libeppic.a eppic_util.o eppic_node.o eppic_var.o eppic_func.o eppic_str.o eppic_op.o eppic_num.o eppic_stat.o eppic_builtin.o eppic_type.o eppic_case.o eppic_api.o eppic_member.o eppic_alloc.o eppic_define.o eppic_input.o eppic_print.o eppicpp.tab.o eppic.tab.o lex.eppic.o lex.eppicpp.o baseops.o ar: eppic_util.o: file format not recognized See eppic commit 0037321e64952b4feb3bd37761fb1067266e9e72 for more details. Signed-off-by: Kairui Song --- ...move-duplicated-variable-declaration.patch | 36 ------------------- kexec-tools.spec | 4 +-- 2 files changed, 1 insertion(+), 39 deletions(-) delete mode 100644 kexec-tools-2.0.20-eppic-Remove-duplicated-variable-declaration.patch diff --git a/kexec-tools-2.0.20-eppic-Remove-duplicated-variable-declaration.patch b/kexec-tools-2.0.20-eppic-Remove-duplicated-variable-declaration.patch deleted file mode 100644 index 8d77b9b..0000000 --- a/kexec-tools-2.0.20-eppic-Remove-duplicated-variable-declaration.patch +++ /dev/null @@ -1,36 +0,0 @@ -From 2837fb1f5f8362976c188b30ebe50dc8b0377f64 Mon Sep 17 00:00:00 2001 -From: Kairui Song -Date: Wed, 29 Jan 2020 11:33:18 +0800 -Subject: [PATCH] Remove duplicated variable declaration - -When building on Fedora 32, following error is observed: - -... -/usr/bin/ld: ../eppic/libeppic/libeppic.a(eppic_stat.o):/builddir/build/BUILD/kexec-tools-2.0.20/eppic/libeppic/eppic.h:474: multiple definition of `lastv'; -../eppic/libeppic/libeppic.a(eppic_func.o):/builddir/build/BUILD/kexec-tools-2.0.20/eppic/libeppic/eppic.h:474: first defined here -... - -And apparently, the variable is wrongly declared multiple times. So -remove duplicated declaration. - -Signed-off-by: Kairui Song ---- - libeppic/eppic.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/libeppic/eppic.h b/libeppic/eppic.h -index 5664583..836b475 100644 ---- a/eppic-d84c3541035d95077aa8571f5d5c3e07c6ef510b/libeppic/eppic.h -+++ b/eppic-d84c3541035d95077aa8571f5d5c3e07c6ef510b/libeppic/eppic.h -@@ -471,7 +471,7 @@ type_t *eppic_addstorage(type_t *t1, type_t *t2); - type_t *eppic_getvoidstruct(int ctype); - - extern int lineno, needvar, instruct, nomacs, eppic_legacy; --node_t *lastv; -+extern node_t *lastv; - - #define NULLNODE ((node_t*)0) - --- -2.24.1 - diff --git a/kexec-tools.spec b/kexec-tools.spec index 00cf64c..fa5c707 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,4 +1,4 @@ -%global eppic_ver d84c3541035d95077aa8571f5d5c3e07c6ef510b +%global eppic_ver e8844d3793471163ae4a56d8f95897be9e5bd554 %global eppic_shortver %(c=%{eppic_ver}; echo ${c:0:7}) %global mkdf_ver 1.6.8 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) @@ -101,7 +101,6 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # -Patch601: ./kexec-tools-2.0.20-eppic-Remove-duplicated-variable-declaration.patch Patch603: ./kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ringbuffer.patch Patch604: ./kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch Patch605: ./kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch @@ -120,7 +119,6 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} -%patch601 -p1 %patch603 -p1 %patch604 -p1 %patch605 -p1 From ad655087c994fba8f0293e1db47c66e35dcecaa3 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 5 Apr 2021 02:33:03 +0800 Subject: [PATCH 017/454] Release 2.0.21-8 Signed-off-by: Kairui Song --- kexec-tools.spec | 13 ++++++++++++- sources | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index fa5c707..24c6b36 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.21 -Release: 7%{?dist} +Release: 8%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -360,6 +360,17 @@ done %endif %changelog +* Sat Apr 03 2021 Kairui Song - 2.0.21-8 +- Update eppic to latest upstream snapshot +- mkdumprd: prompt the user to install nfs-utils when mounting NFS fs failed +- Fix incorrect permissions on kdump dmesg file +- Fix incorrect vmcore permissions when dumped through ssh +- (origin/main) Stop reloading kdump service on CPU hotplug event for FADump +- Rebuilt for updated systemd-rpm-macros +- fadump: improve fadump-howto.txt about remote dump target setup +- kdumpctl: enable secure boot on ppc64le LPARs +- add dependency on ipcalc + * Tue Mar 02 2021 Zbigniew Jędrzejewski-Szmek - 2.0.21-7 - Rebuilt for updated systemd-rpm-macros See https://pagure.io/fesco/issue/2583. diff --git a/sources b/sources index 58d314e..c0e1169 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ -SHA512 (eppic-d84c354.tar.gz) = 455b3386c3e4cc546b858f1f8b0e6874072aaae708ebe072452fb5f0b6a81b1f3a315b40f94c3967f38525cadd276864a7bc7f0f12fa421655dcc3b15b70914d SHA512 (makedumpfile-1.6.8.tar.gz) = 15e60688b06013bf86e339ec855774ea2c904d425371ea867101704ba0611c69da891eb3cc96f67eb10197d8c42d217ea28bf11bcaa93ddc2495cbf984c0b7ec SHA512 (kexec-tools-2.0.21.tar.xz) = f487d2e243c2c4f29fbc9da7d06806f65210f717904655fc84d8d162b9c4614c3dd62e1bb47104a79f0dc2af04e462baf764fb309b5d7e6d287264cb48fd2a3e +SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 From c6021648f1db52a5e2eee31ec409efe468fe5af2 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 19 Mar 2021 18:21:11 +0800 Subject: [PATCH 018/454] Don't iterate the whole /sys/devices just to find drm device On some large systems, /sys/devices is huge and it's not a wise idea to iterate it. `find` may cause tremendous contention on the kernfs_mutex when there are already stress on /sys, and it will perform very very poorly. Simply check if drm class presents should be good enough. Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- dracut-module-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 8316589..affd711 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -58,7 +58,7 @@ depends() { _dep="$_dep znet" fi - if [ -n "$( find /sys/devices -name drm )" ] || [ -d /sys/module/hyperv_fb ]; then + if [ -n "$( ls -A /sys/class/drm 2>/dev/null )" ] || [ -d /sys/module/hyperv_fb ]; then add_opt_module drm fi From 8b4b7bf808117ccf3a4be5c9dc16ad1f008659a3 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 26 Mar 2021 10:22:09 +0800 Subject: [PATCH 019/454] Don't use die in dracut-module-setup.sh die (in dracut-lib.sh) is supposed to be used in the initramfs environment. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index affd711..af8336c 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -334,7 +334,10 @@ kdump_setup_znet() { kdump_get_ip_route() { local _route=$(/sbin/ip -o route get to $1 2>&1) - [ $? != 0 ] && die "Bad kdump network destination: $1" + if [[ $? != 0 ]]; then + derror "Bad kdump network destination: $1" + exit 1 + fi echo $_route } From 1ca1b71780b83aa7ede1246d435c9a4207473a3b Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 8 Apr 2021 11:44:26 +0800 Subject: [PATCH 020/454] Implement IP netmask calculation to replace "ipcalc -m" Recently, dracut-network drops depedency on dhcp-client which requires ipcalc. Thus the dependency chain "kexec-tools -> dracut-network -> dhcp-client -> ipcalc" is broken. When NIC is configured to a static IP, kexec-tools depended on "ipcalc -m" to get netmask. This commit implements the shell equivalent of "ipcalc -m". The following test code shows cal_netmask_by_prefix is consistent with "ipcalc -m", #!/bin/bash . dracut-module-setup.sh for i in {0..128}; do mask_expected=$(ipcalc -m fe::/$i| cut -d"=" -f2) mask_actual=$(cal_netmask_by_prefix $i "-6") if [[ "$mask_expected" != "$mask_actual" ]]; then echo "prefix="$i, "expected="$mask_expected, "acutal="$mask_actual exit fi done echo "IPv6 tests passed" for i in {0..32}; do mask_expected=$(ipcalc -m 8.8.8.8/$i| cut -d"=" -f2) mask_actual=$(cal_netmask_by_prefix $i "") if [[ "$mask_expected" != "$mask_actual" ]]; then echo "prefix="$i, "expected="$mask_expected, "acutal="$mask_actual exit fi done echo "IPv4 tests passed" i=-2 res=$(cal_netmask_by_prefix "$i" "") if [[ $? -ne 1 ]]; then echo "cal_netmask_by_prefix should exit when prefix<0" exit fi res=$(cal_netmask_by_prefix "$i" "") if [[ $? -ne 1 ]]; then echo "cal_netmask_by_prefix should exit when prefix<0" exit fi i=33 $(cal_netmask_by_prefix $i "") if [[ $? -ne 1 ]]; then echo "cal_netmask_by_prefix should exit when prefix>32 for IPv4" exit fi i=129 $(cal_netmask_by_prefix $i "-6") if [[ $? -ne 1 ]]; then echo "cal_netmask_by_prefix should exit when prefix>128 for IPv4" exit fi echo "Bad prefixes tests passed" echo "All tests passed" Reported-by: Jie Li Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 119 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index af8336c..066d0ce 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -121,12 +121,122 @@ kdump_setup_dns() { done < "/etc/resolv.conf" } +# $1: repeat times +# $2: string to be repeated +# $3: separator +repeatedly_join_str() { + local _count="$1" + local _str="$2" + local _separator="$3" + local i _res + + if [[ "$_count" -le 0 ]]; then + echo -n "" + return + fi + + i=0 + _res="$_str" + ((_count--)) + + while [[ "$i" -lt "$_count" ]]; do + ((i++)) + _res="${_res}${_separator}${_str}" + done + echo -n "$_res" +} + +# $1: prefix +# $2: ipv6_flag="-6" indicates it's IPv6 +# Given a prefix, calculate the netmask (equivalent of "ipcalc -m") +# by concatenating three parts, +# 1) the groups with all bits set 1 +# 2) a group with partial bits set to 0 +# 3) the groups with all bits set to 0 +cal_netmask_by_prefix() { + local _prefix="$1" + local _ipv6_flag="$2" _ipv6 + local _bits_per_octet=8 + local _count _res _octets_per_group _octets_total _seperator _total_groups + local _max_group_value _max_group_value_repr _bits_per_group _tmp _zero_bits + + if [[ "$_ipv6_flag" == "-6" ]]; then + _ipv6=1 + else + _ipv6=0 + fi + + if [[ "$_prefix" -lt 0 || "$_prefix" -gt 128 ]] || \ + ( ((!_ipv6)) && [[ "$_prefix" -gt 32 ]] ); then + derror "Bad prefix:$_prefix for calculating netmask" + exit 1 + fi + + if ((_ipv6)); then + _octets_per_group=2 + _octets_total=16 + _seperator=":" + else + _octets_per_group=1 + _octets_total=4 + _seperator="." + fi + + _total_groups=$((_octets_total/_octets_per_group)) + _bits_per_group=$((_octets_per_group * _bits_per_octet)) + _max_group_value=$(((1 << _bits_per_group) - 1)) + + if ((_ipv6)); then + _max_group_value_repr=$(printf "%x" $_max_group_value) + else + _max_group_value_repr="$_max_group_value" + fi + + _count=$((_prefix/_octets_per_group/_bits_per_octet)) + _first_part=$(repeatedly_join_str "$_count" "$_max_group_value_repr" "$_seperator") + _res="$_first_part" + + _tmp=$((_octets_total*_bits_per_octet-_prefix)) + _zero_bits=$(expr $_tmp % $_bits_per_group) + if [[ "$_zero_bits" -ne 0 ]]; then + _second_part=$((_max_group_value >> _zero_bits << _zero_bits)) + if ((_ipv6)); then + _second_part=$(printf "%x" $_second_part) + fi + ((_count++)) + if [[ -z "$_first_part" ]]; then + _res="$_second_part" + else + _res="${_first_part}${_seperator}${_second_part}" + fi + fi + + _count=$((_total_groups-_count)) + if [[ "$_count" -eq 0 ]]; then + echo -n "$_res" + return + fi + + if ((_ipv6)) && [[ "$_count" -gt 1 ]] ; then + # use condensed notion for IPv6 + _third_part=":" + else + _third_part=$(repeatedly_join_str "$_count" "0" "$_seperator") + fi + + if [[ -z "$_res" ]] && ((!_ipv6)) ; then + echo -n "${_third_part}" + else + echo -n "${_res}${_seperator}${_third_part}" + fi +} + #$1: netdev name #$2: srcaddr #if it use static ip echo it, or echo null kdump_static_ip() { local _netdev="$1" _srcaddr="$2" _ipv6_flag - local _netmask _gateway _ipaddr _target _nexthop + local _netmask _gateway _ipaddr _target _nexthop _prefix _ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}") @@ -144,7 +254,12 @@ kdump_static_ip() { _srcaddr="[$_srcaddr]" _gateway="[$_gateway]" else - _netmask=$(ipcalc -m $_ipaddr | cut -d'=' -f2) + _prefix=$(cut -d'/' -f2 <<< "$_ipaddr") + _netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6_flag") + if [[ "$?" -ne 0 ]]; then + derror "Failed to calculate netmask for $_ipaddr" + exit 1 + fi fi echo -n "${_srcaddr}::${_gateway}:${_netmask}::" fi From eca77117062d0a8029ed68bd1cad775db406548a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 8 Apr 2021 11:44:27 +0800 Subject: [PATCH 021/454] Drop dependency on ipcalc A shell equivalent of "ipcalc -m" has been implemented. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- kexec-tools.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 24c6b36..5a1fd22 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -63,7 +63,6 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Recommends: dracut-squash >= 050 Requires: ethtool -Requires: ipcalc BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext From 75bdcb7399b6fe48032a8db534e18b01206601bc Mon Sep 17 00:00:00 2001 From: Kelvin Fan Date: Fri, 16 Apr 2021 22:31:13 +0000 Subject: [PATCH 022/454] Write to `/var/lib/kdump` if $KDUMP_BOOTDIR not writable The `/boot` directory on some operating systems might be read-only. If we cannot write to `$KDUMP_BOOTDIR` when generating the kdump initrd, attempt to place the generated initrd at `/var/lib/kdump` instead. Signed-off by: Kelvin Fan Acked-by: Kairui Song --- 60-kdump.install | 14 ++++++++++---- kdump-lib.sh | 24 +++++++++++++++++------- kdumpctl | 4 ++-- kexec-tools.spec | 2 ++ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/60-kdump.install b/60-kdump.install index 0a3b40e..5b0e021 100755 --- a/60-kdump.install +++ b/60-kdump.install @@ -2,17 +2,23 @@ COMMAND="$1" KERNEL_VERSION="$2" -BOOT_DIR_ABS="$3" +KDUMP_INITRD_DIR_ABS="$3" KERNEL_IMAGE="$4" if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then exit 0 fi -if [[ -d "$BOOT_DIR_ABS" ]]; then +if [[ -d "$KDUMP_INITRD_DIR_ABS" ]]; then KDUMP_INITRD="initrdkdump" else - BOOT_DIR_ABS="/boot" + # If `KDUMP_BOOTDIR` is not writable, then the kdump + # initrd must have been placed at `/var/lib/kdump` + if [[ ! -w "/boot" ]]; then + KDUMP_INITRD_DIR_ABS="/var/lib/kdump" + else + KDUMP_INITRD_DIR_ABS="/boot" + fi KDUMP_INITRD="initramfs-${KERNEL_VERSION}kdump.img" fi @@ -23,7 +29,7 @@ case "$COMMAND" in # and managed by kdump service ;; remove) - rm -f -- "$BOOT_DIR_ABS/$KDUMP_INITRD" + rm -f -- "$KDUMP_INITRD_DIR_ABS/$KDUMP_INITRD" ret=$? ;; esac diff --git a/kdump-lib.sh b/kdump-lib.sh index 21271cf..5f53a8a 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -733,20 +733,30 @@ prepare_kdump_bootinfo() boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" for initrd in $boot_initrdlist; do if [ -f "$KDUMP_BOOTDIR/$initrd" ]; then - DEFAULT_INITRD="$KDUMP_BOOTDIR/$initrd" + defaut_initrd_base="$initrd" + DEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base" break fi done - # Get kdump initrd from default initrd filename + # Create kdump initrd basename from default initrd basename # initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img # initrd => initrdkdump - if [[ -z "$DEFAULT_INITRD" ]]; then - KDUMP_INITRD=${KDUMP_BOOTDIR}/initramfs-${KDUMP_KERNELVER}kdump.img - elif [[ $(basename $DEFAULT_INITRD) == *.* ]]; then - KDUMP_INITRD=${DEFAULT_INITRD%.*}kdump.${DEFAULT_INITRD##*.} + if [[ -z "$defaut_initrd_base" ]]; then + kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img + elif [[ $defaut_initrd_base == *.* ]]; then + kdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.} else - KDUMP_INITRD=${DEFAULT_INITRD}kdump + kdump_initrd_base=${defaut_initrd_base}kdump + fi + + # Place kdump initrd in `/var/lib/kdump` if `KDUMP_BOOTDIR` not writable + if [[ ! -w "$KDUMP_BOOTDIR" ]];then + var_target_initrd_dir="/var/lib/kdump" + mkdir -p "$var_target_initrd_dir" + KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base" + else + KDUMP_INITRD="$KDUMP_BOOTDIR/$kdump_initrd_base" fi } diff --git a/kdumpctl b/kdumpctl index c3311ad..b0846fa 100755 --- a/kdumpctl +++ b/kdumpctl @@ -151,8 +151,8 @@ rebuild_kdump_initrd() rebuild_initrd() { - if [[ ! -w "$KDUMP_BOOTDIR" ]];then - derror "$KDUMP_BOOTDIR does not have write permission. Can not rebuild $TARGET_INITRD" + if [[ ! -w $(dirname $TARGET_INITRD) ]];then + derror "$(dirname $TARGET_INITRD) does not have write permission. Cannot rebuild $TARGET_INITRD" return 1 fi diff --git a/kexec-tools.spec b/kexec-tools.spec index 5a1fd22..cd0ed19 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -169,6 +169,7 @@ mkdir -p $RPM_BUILD_ROOT%{_unitdir} mkdir -p -m755 $RPM_BUILD_ROOT%{_bindir} mkdir -p -m755 $RPM_BUILD_ROOT%{_libdir} mkdir -p -m755 $RPM_BUILD_ROOT%{_prefix}/lib/kdump +mkdir -p -m755 $RPM_BUILD_ROOT%{_sharedstatedir}/kdump install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/kdumpctl install -m 755 build/sbin/kexec $RPM_BUILD_ROOT/usr/sbin/kexec @@ -334,6 +335,7 @@ done %dir %{_sysconfdir}/kdump %dir %{_sysconfdir}/kdump/pre.d %dir %{_sysconfdir}/kdump/post.d +%dir %{_sharedstatedir}/kdump %{_mandir}/man8/kdumpctl.8.gz %{_mandir}/man8/kexec.8.gz %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 From afda4f4961dbf09f7f64cadd936e01a4675ea31f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 25 Apr 2021 15:58:25 +0800 Subject: [PATCH 023/454] get kdump ifname once in kdump_install_net Signed-off-by: Coiby Xu Acked-by: Kairui Song > $_ip_conf fi @@ -543,8 +544,8 @@ kdump_install_net() { # gateway. if [ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ] && [ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then - echo "kdumpnic=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/60kdumpnic.conf - echo "bootdev=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/70bootdev.conf + echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf + echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf fi } From 586d767697100598e167993e7cc29b3732d5406a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 25 Apr 2021 15:58:26 +0800 Subject: [PATCH 024/454] pass kdumpnic to kdump_setup_/bond/bridge/vlan directly This avoids calling kdump_setup_ifname repeatedly. Signed-off-by: Coiby Xu Acked-by: Kairui Song > ${initdir}/etc/cmdline.d/41bridge.conf + echo -n " ifname=$kdumpnic:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf fi _brif+="$_kdumpdev," done @@ -373,12 +372,11 @@ kdump_setup_bridge() { } kdump_setup_bond() { - local _netdev=$1 - local _dev _mac _slaves _kdumpdev + local _netdev=$1 kdumpnic=$2 + local _dev _mac _slaves for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do _mac=$(kdump_get_perm_addr $_dev) - _kdumpdev=$(kdump_setup_ifname $_dev) - echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf + echo -n " ifname=$kdumpnic:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf _slaves+="$_kdumpdev," done echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf @@ -391,12 +389,11 @@ kdump_setup_bond() { } kdump_setup_team() { - local _netdev=$1 - local _dev _mac _slaves _kdumpdev + local _netdev=$1 kdumpnic=$2 + local _dev _mac _slaves for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do _mac=$(kdump_get_perm_addr $_dev) - _kdumpdev=$(kdump_setup_ifname $_dev) - echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf + echo -n " ifname=$kdumpnic:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf _slaves+="$_kdumpdev," done echo " team=$_netdev:$(echo $_slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf @@ -414,7 +411,7 @@ kdump_setup_team() { } kdump_setup_vlan() { - local _netdev=$1 + local _netdev=$1 kdumpnic=$2 local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" local _netmac="$(kdump_get_mac_addr $_phydev)" local _kdumpdev @@ -425,10 +422,10 @@ kdump_setup_vlan() { exit 1 elif kdump_is_bond "$_phydev"; then kdump_setup_bond "$_phydev" - echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf + echo " vlan=$kdumpnic:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf else _kdumpdev="$(kdump_setup_ifname $_phydev)" - echo " vlan=$(kdump_setup_ifname $_netdev):$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf + echo " vlan=$kdumpnic:$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf fi } @@ -516,13 +513,13 @@ kdump_install_net() { fi if kdump_is_bridge "$_netdev"; then - kdump_setup_bridge "$_netdev" + kdump_setup_bridge "$_netdev" "$kdumpnic" elif kdump_is_bond "$_netdev"; then - kdump_setup_bond "$_netdev" + kdump_setup_bond "$_netdev" "$kdumpnic" elif kdump_is_team "$_netdev"; then - kdump_setup_team "$_netdev" + kdump_setup_team "$_netdev" "$kdumpnic" elif kdump_is_vlan "$_netdev"; then - kdump_setup_vlan "$_netdev" + kdump_setup_vlan "$_netdev" "$kdumpnic" else _ifname_opts=" ifname=$kdumpnic:$_netmac" echo "$_ifname_opts" >> $_ip_conf From 18ffd3cb174e01ea18c8c56ac7b1503168bf0ec2 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 25 Apr 2021 15:58:27 +0800 Subject: [PATCH 025/454] rd.route should use the name from kdump_setup_ifname This fix bz1854037 which happens because kexec-tools generates rd.route for eth0 instead of for kdump-eth0, 1. "rd.route=168.63.129.16:10.0.0.1:eth0 rd.route=169.254.169.254:10.0.0.1:eth0" is passed to the dracut cmdline by kexec-tools 2. In the 2rd kernel, - dracut/modules.d/40network/net-lib.sh will write /tmp/net.route.eth0 based on rd.route - dracut/modules.d/45ifcfg/write-ifcfg.sh will copy /tmp/net.route.eth0 to /tmp/icfg and then copytree /tmp/ifcfg to /run/initramfs/state/etc/sysconfig/network-scripts 3. NetworkManager will try to get an IP for eth0 regardless of the fact it's a slave NIC and time out ``` $ ip link show 2: kdump-eth0: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 00:0d:3a:11:86:8b brd ff:ff:ff:ff:ff:ff 3: eth0: mtu 1500 qdisc mq master kdump-eth0 state UP mode DEFAULT group default qlen 1000 ``` Reported-by: Huijing Hei Signed-off-by: Coiby Xu Acked-by: Kairui Song > ${initdir}/etc/cmdline.d/45route-static.conf - kdump_handle_mulitpath_route $_netdev $_srcaddr + kdump_handle_mulitpath_route $_netdev $_srcaddr $kdumpnic } kdump_handle_mulitpath_route() { - local _netdev="$1" _srcaddr="$2" _ipv6_flag + local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag local _target _nexthop _route _weight _max_weight _rule if is_ipv6_address $_srcaddr; then @@ -299,9 +299,9 @@ kdump_handle_mulitpath_route() { _nexthop=`echo "$_route" | cut -d ' ' -f3` _max_weight=$_weight if [ "x" != "x"$_ipv6_flag ]; then - _rule="rd.route=[$_target]:[$_nexthop]:$_netdev" + _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" else - _rule="rd.route=$_target:$_nexthop:$_netdev" + _rule="rd.route=$_target:$_nexthop:$kdumpnic" fi fi else @@ -491,7 +491,7 @@ kdump_install_net() { kdump_setup_znet $_netdev fi - _static=$(kdump_static_ip $_netdev $_srcaddr) + _static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) if [ -n "$_static" ]; then _proto=none elif is_ipv6_address $_srcaddr; then From 4753ab2c70100c570f32f65245b3173588374a76 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 28 Apr 2021 15:00:21 +0800 Subject: [PATCH 026/454] Revert "rd.route should use the name from kdump_setup_ifname" This reverts commit 18ffd3cb174e01ea18c8c56ac7b1503168bf0ec2. --- dracut-module-setup.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 80df59c..d1c2c8d 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -235,7 +235,7 @@ cal_netmask_by_prefix() { #$2: srcaddr #if it use static ip echo it, or echo null kdump_static_ip() { - local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag + local _netdev="$1" _srcaddr="$2" _ipv6_flag local _netmask _gateway _ipaddr _target _nexthop _prefix _ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}") @@ -273,14 +273,14 @@ kdump_static_ip() { _target="[$_target]" _nexthop="[$_nexthop]" fi - echo "rd.route=$_target:$_nexthop:$kdumpnic" + echo "rd.route=$_target:$_nexthop:$_netdev" done >> ${initdir}/etc/cmdline.d/45route-static.conf - kdump_handle_mulitpath_route $_netdev $_srcaddr $kdumpnic + kdump_handle_mulitpath_route $_netdev $_srcaddr } kdump_handle_mulitpath_route() { - local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag + local _netdev="$1" _srcaddr="$2" _ipv6_flag local _target _nexthop _route _weight _max_weight _rule if is_ipv6_address $_srcaddr; then @@ -299,9 +299,9 @@ kdump_handle_mulitpath_route() { _nexthop=`echo "$_route" | cut -d ' ' -f3` _max_weight=$_weight if [ "x" != "x"$_ipv6_flag ]; then - _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" + _rule="rd.route=[$_target]:[$_nexthop]:$_netdev" else - _rule="rd.route=$_target:$_nexthop:$kdumpnic" + _rule="rd.route=$_target:$_nexthop:$_netdev" fi fi else @@ -491,7 +491,7 @@ kdump_install_net() { kdump_setup_znet $_netdev fi - _static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) + _static=$(kdump_static_ip $_netdev $_srcaddr) if [ -n "$_static" ]; then _proto=none elif is_ipv6_address $_srcaddr; then From b0156e9b64778e318039cb12933562d79406d46f Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 28 Apr 2021 15:00:15 +0800 Subject: [PATCH 027/454] Revert "pass kdumpnic to kdump_setup_/bond/bridge/vlan directly" This reverts commit 586d767697100598e167993e7cc29b3732d5406a. --- dracut-module-setup.sh | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index d1c2c8d..c6c1a9b 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -352,8 +352,8 @@ kdump_setup_ifname() { } kdump_setup_bridge() { - local _netdev=$1 kdumpnic=$2 - local _brif _dev _mac + local _netdev=$1 + local _brif _dev _mac _kdumpdev for _dev in `ls /sys/class/net/$_netdev/brif/`; do _kdumpdev=$_dev if kdump_is_bond "$_dev"; then @@ -364,7 +364,8 @@ kdump_setup_bridge() { kdump_setup_vlan "$_dev" else _mac=$(kdump_get_mac_addr $_dev) - echo -n " ifname=$kdumpnic:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf + _kdumpdev=$(kdump_setup_ifname $_dev) + echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf fi _brif+="$_kdumpdev," done @@ -372,11 +373,12 @@ kdump_setup_bridge() { } kdump_setup_bond() { - local _netdev=$1 kdumpnic=$2 - local _dev _mac _slaves + local _netdev=$1 + local _dev _mac _slaves _kdumpdev for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do _mac=$(kdump_get_perm_addr $_dev) - echo -n " ifname=$kdumpnic:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf + _kdumpdev=$(kdump_setup_ifname $_dev) + echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf _slaves+="$_kdumpdev," done echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf @@ -389,11 +391,12 @@ kdump_setup_bond() { } kdump_setup_team() { - local _netdev=$1 kdumpnic=$2 - local _dev _mac _slaves + local _netdev=$1 + local _dev _mac _slaves _kdumpdev for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do _mac=$(kdump_get_perm_addr $_dev) - echo -n " ifname=$kdumpnic:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf + _kdumpdev=$(kdump_setup_ifname $_dev) + echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf _slaves+="$_kdumpdev," done echo " team=$_netdev:$(echo $_slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf @@ -411,7 +414,7 @@ kdump_setup_team() { } kdump_setup_vlan() { - local _netdev=$1 kdumpnic=$2 + local _netdev=$1 local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" local _netmac="$(kdump_get_mac_addr $_phydev)" local _kdumpdev @@ -422,10 +425,10 @@ kdump_setup_vlan() { exit 1 elif kdump_is_bond "$_phydev"; then kdump_setup_bond "$_phydev" - echo " vlan=$kdumpnic:$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf + echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf else _kdumpdev="$(kdump_setup_ifname $_phydev)" - echo " vlan=$kdumpnic:$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf + echo " vlan=$(kdump_setup_ifname $_netdev):$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf fi } @@ -513,13 +516,13 @@ kdump_install_net() { fi if kdump_is_bridge "$_netdev"; then - kdump_setup_bridge "$_netdev" "$kdumpnic" + kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then - kdump_setup_bond "$_netdev" "$kdumpnic" + kdump_setup_bond "$_netdev" elif kdump_is_team "$_netdev"; then - kdump_setup_team "$_netdev" "$kdumpnic" + kdump_setup_team "$_netdev" elif kdump_is_vlan "$_netdev"; then - kdump_setup_vlan "$_netdev" "$kdumpnic" + kdump_setup_vlan "$_netdev" else _ifname_opts=" ifname=$kdumpnic:$_netmac" echo "$_ifname_opts" >> $_ip_conf From 8d0ef743e0df7a77b4c67f6a98363c1a92de4038 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 28 Apr 2021 15:00:12 +0800 Subject: [PATCH 028/454] Revert "get kdump ifname once in kdump_install_net" This reverts commit afda4f4961dbf09f7f64cadd936e01a4675ea31f. --- dracut-module-setup.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index c6c1a9b..066d0ce 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -480,7 +480,7 @@ kdump_get_remote_ip() # initramfs accessing giving destination # $1: destination host kdump_install_net() { - local _destaddr _srcaddr _route _netdev kdumpnic + local _destaddr _srcaddr _route _netdev local _static _proto _ip_conf _ip_opts _ifname_opts _destaddr=$(kdump_get_remote_ip $1) @@ -488,7 +488,6 @@ kdump_install_net() { _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") _netmac=$(kdump_get_mac_addr $_netdev) - kdumpnic=$(kdump_setup_ifname $_netdev) if [ "$(uname -m)" = "s390x" ]; then kdump_setup_znet $_netdev @@ -504,7 +503,7 @@ kdump_install_net() { fi _ip_conf="${initdir}/etc/cmdline.d/40ip.conf" - _ip_opts=" ip=${_static}$kdumpnic:${_proto}" + _ip_opts=" ip=${_static}$(kdump_setup_ifname $_netdev):${_proto}" # dracut doesn't allow duplicated configuration for same NIC, even they're exactly the same. # so we have to avoid adding duplicates @@ -524,7 +523,7 @@ kdump_install_net() { elif kdump_is_vlan "$_netdev"; then kdump_setup_vlan "$_netdev" else - _ifname_opts=" ifname=$kdumpnic:$_netmac" + _ifname_opts=" ifname=$(kdump_setup_ifname $_netdev):$_netmac" echo "$_ifname_opts" >> $_ip_conf fi @@ -544,8 +543,8 @@ kdump_install_net() { # gateway. if [ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ] && [ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then - echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf - echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf + echo "kdumpnic=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/60kdumpnic.conf + echo "bootdev=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/70bootdev.conf fi } From d0e9c51e0de57273a99af8484515f213b8414e65 Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Thu, 22 Apr 2021 18:21:59 +0530 Subject: [PATCH 029/454] fadump: fix dump capture failure to root disk If the dump target is the root disk, kdump scripts add an entry in /etc/fstab for root disk with /sysroot as the mount point. The root disk, passed through root=<> kernel commandline parameter, is mounted at /sysroot in read-only mode before switching from initial ramdisk. So, in fadump mode, a remount of /sysroot to read-write mode is needed to capture dump successfully, because /sysroot is already mounted as read-only based on root=<> boot parameter. Commit e8ef4db8ff91 ("Fix dump_fs mount point detection and fallback mount") removed initialization of $_op variable, the variable holding the options the dump target was mounted with, leading to the below error as remount was skipped: kdump[586]: saving to /sysroot/var/crash/127.0.0.1-2021-04-22-07:22:08/ kdump.sh[587]: mkdir: cannot create directory '/sysroot/var/crash/127.0.0.1-2021-04-22-07:22:08/': Read-only file system kdump[589]: saving vmcore failed Restore $_op variable initialization in dump_fs() function to fix this. Fixes: e8ef4db8ff91 ("Fix dump_fs mount point detection and fallback mount") Signed-off-by: Hari Bathini Acked-by: Kairui Song --- kdump-lib-initramfs.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 5cb0223..15bbd85 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -119,7 +119,8 @@ dump_fs() { local _exitcode local _mp=$1 - ddebug "dump_fs _mp=$_mp" + local _op=$(get_mount_info OPTIONS target $_mp -f) + ddebug "dump_fs _mp=$_mp _opts=$_op" if ! is_mounted "$_mp"; then dinfo "dump path \"$_mp\" is not mounted, trying to mount..." @@ -139,8 +140,8 @@ dump_fs() # Only remount to read-write mode if the dump target is mounted read-only. if [[ "$_op" = "ro"* ]]; then - dinfo "Mounting Dump target $_dev in rw mode." - mount -o remount,rw $_dev $_mp || return 1 + dinfo "Remounting the dump target in rw mode." + mount -o remount,rw $_mp || return 1 fi mkdir -p $_dump_path || return 1 From e1ab0275c0106bccca7131627c40523ce8b6333b Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 19 Apr 2021 22:13:36 +0800 Subject: [PATCH 030/454] Add --dry-run option to prevent writing the dumpfile Backport from upstream. commit 3422e1d6bc3511c5af9cb05ba74ad97dd93ffd7f Author: Julien Thierry Date: Tue Nov 24 10:45:24 2020 +0000 [PATCH 1/2] Add --dry-run option to prevent writing the dumpfile Add a --dry-run option to run all operations without writing the dump to the output file. Signed-off-by: Julien Thierry Signed-off-by: Kazuhito Hagio Signed-off-by: Tao Liu Acked-by: Kairui Song --- ...0.21-makedumpfile-Add-dry-run-option.patch | 177 ++++++++++++++++++ kexec-tools.spec | 2 + 2 files changed, 179 insertions(+) create mode 100644 kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch diff --git a/kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch b/kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch new file mode 100644 index 0000000..ffe8a39 --- /dev/null +++ b/kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch @@ -0,0 +1,177 @@ +From 3422e1d6bc3511c5af9cb05ba74ad97dd93ffd7f Mon Sep 17 00:00:00 2001 +From: Julien Thierry +Date: Tue, 24 Nov 2020 10:45:24 +0000 +Subject: [PATCH 02/12] [PATCH 1/2] Add --dry-run option to prevent writing the + dumpfile + +Add a --dry-run option to run all operations without writing the +dump to the output file. + +Signed-off-by: Julien Thierry +Signed-off-by: Kazuhito Hagio +--- + makedumpfile.8 | 6 ++++++ + makedumpfile.c | 37 ++++++++++++++++++++++++++++++------- + makedumpfile.h | 2 ++ + print_info.c | 3 +++ + 4 files changed, 41 insertions(+), 7 deletions(-) + +diff --git a/makedumpfile-1.6.8/makedumpfile.8 b/makedumpfile-1.6.8/makedumpfile.8 +index b68a7e3..5e902cd 100644 +--- a/makedumpfile-1.6.8/makedumpfile.8 ++++ b/makedumpfile-1.6.8/makedumpfile.8 +@@ -637,6 +637,12 @@ Show the version of makedumpfile. + Only check whether the command-line parameters are valid or not, and exit. + Preferable to be given as the first parameter. + ++.TP ++\fB\-\-dry-run\fR ++Do not write the output dump file while still performing operations specified ++by other options. ++This option cannot be used with the --dump-dmesg, --reassemble and -g options. ++ + .SH ENVIRONMENT VARIABLES + + .TP 8 +diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c +index ecd63fa..8c80c49 100644 +--- a/makedumpfile-1.6.8/makedumpfile.c ++++ b/makedumpfile-1.6.8/makedumpfile.c +@@ -1372,6 +1372,8 @@ open_dump_file(void) + if (info->flag_flatten) { + fd = STDOUT_FILENO; + info->name_dumpfile = filename_stdout; ++ } else if (info->flag_dry_run) { ++ fd = -1; + } else if ((fd = open(info->name_dumpfile, open_flags, + S_IRUSR|S_IWUSR)) < 0) { + ERRMSG("Can't open the dump file(%s). %s\n", +@@ -4711,6 +4713,9 @@ write_and_check_space(int fd, void *buf, size_t buf_size, char *file_name) + { + int status, written_size = 0; + ++ if (info->flag_dry_run) ++ return TRUE; ++ + while (written_size < buf_size) { + status = write(fd, buf + written_size, + buf_size - written_size); +@@ -4748,13 +4753,12 @@ write_buffer(int fd, off_t offset, void *buf, size_t buf_size, char *file_name) + } + if (!write_and_check_space(fd, &fdh, sizeof(fdh), file_name)) + return FALSE; +- } else { +- if (lseek(fd, offset, SEEK_SET) == failed) { +- ERRMSG("Can't seek the dump file(%s). %s\n", +- file_name, strerror(errno)); +- return FALSE; +- } ++ } else if (!info->flag_dry_run && ++ lseek(fd, offset, SEEK_SET) == failed) { ++ ERRMSG("Can't seek the dump file(%s). %s\n", file_name, strerror(errno)); ++ return FALSE; + } ++ + if (!write_and_check_space(fd, buf, buf_size, file_name)) + return FALSE; + +@@ -9112,7 +9116,7 @@ close_dump_memory(void) + void + close_dump_file(void) + { +- if (info->flag_flatten) ++ if (info->flag_flatten || info->flag_dry_run) + return; + + if (close(info->fd_dumpfile) < 0) +@@ -10985,6 +10989,11 @@ check_param_for_generating_vmcoreinfo(int argc, char *argv[]) + + return FALSE; + ++ if (info->flag_dry_run) { ++ MSG("--dry-run cannot be used with -g.\n"); ++ return FALSE; ++ } ++ + return TRUE; + } + +@@ -11029,6 +11038,11 @@ check_param_for_reassembling_dumpfile(int argc, char *argv[]) + || info->flag_exclude_xen_dom || info->flag_split) + return FALSE; + ++ if (info->flag_dry_run) { ++ MSG("--dry-run cannot be used with --reassemble.\n"); ++ return FALSE; ++ } ++ + if ((info->splitting_info + = malloc(sizeof(struct splitting_info) * info->num_dumpfile)) + == NULL) { +@@ -11057,6 +11071,11 @@ check_param_for_creating_dumpfile(int argc, char *argv[]) + || (info->flag_read_vmcoreinfo && info->name_xen_syms)) + return FALSE; + ++ if (info->flag_dry_run && info->flag_dmesg) { ++ MSG("--dry-run cannot be used with --dump-dmesg.\n"); ++ return FALSE; ++ } ++ + if (info->flag_flatten && info->flag_split) + return FALSE; + +@@ -11520,6 +11539,7 @@ static struct option longopts[] = { + {"work-dir", required_argument, NULL, OPT_WORKING_DIR}, + {"num-threads", required_argument, NULL, OPT_NUM_THREADS}, + {"check-params", no_argument, NULL, OPT_CHECK_PARAMS}, ++ {"dry-run", no_argument, NULL, OPT_DRY_RUN}, + {0, 0, 0, 0} + }; + +@@ -11686,6 +11706,9 @@ main(int argc, char *argv[]) + info->flag_check_params = TRUE; + message_level = DEFAULT_MSG_LEVEL; + break; ++ case OPT_DRY_RUN: ++ info->flag_dry_run = TRUE; ++ break; + case '?': + MSG("Commandline parameter is invalid.\n"); + MSG("Try `makedumpfile --help' for more information.\n"); +diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h +index 5f50080..4c4222c 100644 +--- a/makedumpfile-1.6.8/makedumpfile.h ++++ b/makedumpfile-1.6.8/makedumpfile.h +@@ -1322,6 +1322,7 @@ struct DumpInfo { + int flag_vmemmap; /* kernel supports vmemmap address space */ + int flag_excludevm; /* -e - excluding unused vmemmap pages */ + int flag_use_count; /* _refcount is named _count in struct page */ ++ int flag_dry_run; /* do not create a vmcore file */ + unsigned long vaddr_for_vtop; /* virtual address for debugging */ + long page_size; /* size of page */ + long page_shift; +@@ -2425,6 +2426,7 @@ struct elf_prstatus { + #define OPT_NUM_THREADS OPT_START+16 + #define OPT_PARTIAL_DMESG OPT_START+17 + #define OPT_CHECK_PARAMS OPT_START+18 ++#define OPT_DRY_RUN OPT_START+19 + + /* + * Function Prototype. +diff --git a/makedumpfile-1.6.8/print_info.c b/makedumpfile-1.6.8/print_info.c +index e0c38b4..d2b0cb7 100644 +--- a/makedumpfile-1.6.8/print_info.c ++++ b/makedumpfile-1.6.8/print_info.c +@@ -308,6 +308,9 @@ print_usage(void) + MSG(" the crashkernel range, then calculates the page number of different kind per\n"); + MSG(" vmcoreinfo. So currently /proc/kcore need be specified explicitly.\n"); + MSG("\n"); ++ MSG(" [--dry-run]:\n"); ++ MSG(" This option runs makedumpfile without writting output dump file.\n"); ++ MSG("\n"); + MSG(" [-D]:\n"); + MSG(" Print debugging message.\n"); + MSG("\n"); +-- +2.29.2 + diff --git a/kexec-tools.spec b/kexec-tools.spec index cd0ed19..0b16728 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -103,6 +103,7 @@ Requires: systemd-udev%{?_isa} Patch603: ./kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ringbuffer.patch Patch604: ./kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch Patch605: ./kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch +Patch606: ./kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -121,6 +122,7 @@ tar -z -x -v -f %{SOURCE19} %patch603 -p1 %patch604 -p1 %patch605 -p1 +%patch606 -p1 %ifarch ppc %define archdef ARCH=ppc From 8973bd7ed0a870ccc3c5b9c77f80d704ca2b59c8 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 19 Apr 2021 22:13:37 +0800 Subject: [PATCH 031/454] Add shorthand --show-stats option to show report stats Backport from upstream: commit 6f3e75a558ed50d6ff0b42e3f61c099b2005b7bb Author: Julien Thierry Date: Tue Nov 24 10:45:25 2020 +0000 [PATCH 2/2] Add shorthand --show-stats option to show report stats Provide shorthand --show-stats option to enable report messages without needing to set a particular value for message-level. Signed-off-by: Julien Thierry Signed-off-by: Kazuhito Hagio Signed-off-by: Tao Liu Acked-by: Kairui Song --- ...file-Add-shorthand-show-stats-option.patch | 107 ++++++++++++++++++ kexec-tools.spec | 2 + 2 files changed, 109 insertions(+) create mode 100644 kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch diff --git a/kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch b/kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch new file mode 100644 index 0000000..4f259ab --- /dev/null +++ b/kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch @@ -0,0 +1,107 @@ +From 6f3e75a558ed50d6ff0b42e3f61c099b2005b7bb Mon Sep 17 00:00:00 2001 +From: Julien Thierry +Date: Tue, 24 Nov 2020 10:45:25 +0000 +Subject: [PATCH 03/12] [PATCH 2/2] Add shorthand --show-stats option to show + report stats + +Provide shorthand --show-stats option to enable report messages +without needing to set a particular value for message-level. + +Signed-off-by: Julien Thierry +Signed-off-by: Kazuhito Hagio +--- + makedumpfile.8 | 5 +++++ + makedumpfile.c | 9 ++++++++- + makedumpfile.h | 1 + + print_info.c | 7 ++++++- + 4 files changed, 20 insertions(+), 2 deletions(-) + +diff --git a/makedumpfile-1.6.8/makedumpfile.8 b/makedumpfile-1.6.8/makedumpfile.8 +index 5e902cd..dcca2dd 100644 +--- a/makedumpfile-1.6.8/makedumpfile.8 ++++ b/makedumpfile-1.6.8/makedumpfile.8 +@@ -643,6 +643,11 @@ Do not write the output dump file while still performing operations specified + by other options. + This option cannot be used with the --dump-dmesg, --reassemble and -g options. + ++.TP ++\fB\-\-show-stats\fR ++Display report messages. This is an alternative to enabling bit 4 in the level ++provided to --message-level. ++ + .SH ENVIRONMENT VARIABLES + + .TP 8 +diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c +index 8c80c49..ba0003a 100644 +--- a/makedumpfile-1.6.8/makedumpfile.c ++++ b/makedumpfile-1.6.8/makedumpfile.c +@@ -11540,13 +11540,14 @@ static struct option longopts[] = { + {"num-threads", required_argument, NULL, OPT_NUM_THREADS}, + {"check-params", no_argument, NULL, OPT_CHECK_PARAMS}, + {"dry-run", no_argument, NULL, OPT_DRY_RUN}, ++ {"show-stats", no_argument, NULL, OPT_SHOW_STATS}, + {0, 0, 0, 0} + }; + + int + main(int argc, char *argv[]) + { +- int i, opt, flag_debug = FALSE; ++ int i, opt, flag_debug = FALSE, flag_show_stats = FALSE; + + if ((info = calloc(1, sizeof(struct DumpInfo))) == NULL) { + ERRMSG("Can't allocate memory for the pagedesc cache. %s.\n", +@@ -11709,6 +11710,9 @@ main(int argc, char *argv[]) + case OPT_DRY_RUN: + info->flag_dry_run = TRUE; + break; ++ case OPT_SHOW_STATS: ++ flag_show_stats = TRUE; ++ break; + case '?': + MSG("Commandline parameter is invalid.\n"); + MSG("Try `makedumpfile --help' for more information.\n"); +@@ -11718,6 +11722,9 @@ main(int argc, char *argv[]) + if (flag_debug) + message_level |= ML_PRINT_DEBUG_MSG; + ++ if (flag_show_stats) ++ message_level |= ML_PRINT_REPORT_MSG; ++ + if (info->flag_check_params) + /* suppress debugging messages */ + message_level = DEFAULT_MSG_LEVEL; +diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h +index 4c4222c..2fcb62e 100644 +--- a/makedumpfile-1.6.8/makedumpfile.h ++++ b/makedumpfile-1.6.8/makedumpfile.h +@@ -2427,6 +2427,7 @@ struct elf_prstatus { + #define OPT_PARTIAL_DMESG OPT_START+17 + #define OPT_CHECK_PARAMS OPT_START+18 + #define OPT_DRY_RUN OPT_START+19 ++#define OPT_SHOW_STATS OPT_START+20 + + /* + * Function Prototype. +diff --git a/makedumpfile-1.6.8/print_info.c b/makedumpfile-1.6.8/print_info.c +index d2b0cb7..ad4184e 100644 +--- a/makedumpfile-1.6.8/print_info.c ++++ b/makedumpfile-1.6.8/print_info.c +@@ -309,7 +309,12 @@ print_usage(void) + MSG(" vmcoreinfo. So currently /proc/kcore need be specified explicitly.\n"); + MSG("\n"); + MSG(" [--dry-run]:\n"); +- MSG(" This option runs makedumpfile without writting output dump file.\n"); ++ MSG(" Do not write the output dump file while still performing operations specified\n"); ++ MSG(" by other options. This option cannot be used with --dump-dmesg, --reassemble\n"); ++ MSG(" and -g options.\n"); ++ MSG("\n"); ++ MSG(" [--show-stats]:\n"); ++ MSG(" Set message-level to print report messages\n"); + MSG("\n"); + MSG(" [-D]:\n"); + MSG(" Print debugging message.\n"); +-- +2.29.2 + diff --git a/kexec-tools.spec b/kexec-tools.spec index 0b16728..ba3c247 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -104,6 +104,7 @@ Patch603: ./kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ring Patch604: ./kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch Patch605: ./kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch Patch606: ./kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch +Patch607: ./kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -123,6 +124,7 @@ tar -z -x -v -f %{SOURCE19} %patch604 -p1 %patch605 -p1 %patch606 -p1 +%patch607 -p1 %ifarch ppc %define archdef ARCH=ppc From 0db060c4e26dc13e0f98553480b0e8af4a186874 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 19 Apr 2021 22:13:38 +0800 Subject: [PATCH 032/454] Show write byte size in report messages Backport from upstream: commit 0ef2ca6c9fa2f61f217a4bf5d7fd70f24e12b2eb Author: Kazuhito Hagio Date: Thu Feb 4 16:29:06 2021 +0900 [PATCH] Show write byte size in report messages Show write byte size in report messages. This value can be different from the size of the actual file because of some holes on dumpfile data structure. $ makedumpfile --show-stats -l -d 1 vmcore dump.ld1 ... Total pages : 0x0000000000080000 Write bytes : 377686445 ... # ls -l dump.ld1 -rw------- 1 root root 377691573 Feb 4 16:28 dump.ld1 Note that this value should not be used with /proc/kcore to determine how much disk space is needed for crash dump, because the real memory usage when a crash occurs can vary widely. Signed-off-by: Kazuhito Hagio Signed-off-by: Tao Liu Acked-by: Kairui Song --- ...w-write-byte-size-in-report-messages.patch | 59 +++++++++++++++++++ kexec-tools.spec | 2 + 2 files changed, 61 insertions(+) create mode 100644 kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch diff --git a/kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch b/kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch new file mode 100644 index 0000000..be89b54 --- /dev/null +++ b/kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch @@ -0,0 +1,59 @@ +From 0ef2ca6c9fa2f61f217a4bf5d7fd70f24e12b2eb Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Thu, 4 Feb 2021 16:29:06 +0900 +Subject: [PATCH 09/12] [PATCH] Show write byte size in report messages + +Show write byte size in report messages. This value can be different +from the size of the actual file because of some holes on dumpfile +data structure. + + $ makedumpfile --show-stats -l -d 1 vmcore dump.ld1 + ... + Total pages : 0x0000000000080000 + Write bytes : 377686445 + ... + # ls -l dump.ld1 + -rw------- 1 root root 377691573 Feb 4 16:28 dump.ld1 + +Note that this value should not be used with /proc/kcore to determine +how much disk space is needed for crash dump, because the real memory +usage when a crash occurs can vary widely. + +Signed-off-by: Kazuhito Hagio +--- + makedumpfile.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c +index fcd766b..894c88e 100644 +--- a/makedumpfile-1.6.8/makedumpfile.c ++++ b/makedumpfile-1.6.8/makedumpfile.c +@@ -48,6 +48,8 @@ char filename_stdout[] = FILENAME_STDOUT; + static unsigned long long cache_hit; + static unsigned long long cache_miss; + ++static unsigned long long write_bytes; ++ + static void first_cycle(mdf_pfn_t start, mdf_pfn_t max, struct cycle *cycle) + { + cycle->start_pfn = round(start, info->pfn_cyclic); +@@ -4715,6 +4717,8 @@ write_and_check_space(int fd, void *buf, size_t buf_size, char *file_name) + { + int status, written_size = 0; + ++ write_bytes += buf_size; ++ + if (info->flag_dry_run) + return TRUE; + +@@ -10002,6 +10006,7 @@ print_report(void) + REPORT_MSG("Memory Hole : 0x%016llx\n", pfn_memhole); + REPORT_MSG("--------------------------------------------------\n"); + REPORT_MSG("Total pages : 0x%016llx\n", info->max_mapnr); ++ REPORT_MSG("Write bytes : %llu\n", write_bytes); + REPORT_MSG("\n"); + REPORT_MSG("Cache hit: %lld, miss: %lld", cache_hit, cache_miss); + if (cache_hit + cache_miss) +-- +2.29.2 + diff --git a/kexec-tools.spec b/kexec-tools.spec index ba3c247..1e6c99e 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -105,6 +105,7 @@ Patch604: ./kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state Patch605: ./kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch Patch606: ./kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch Patch607: ./kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch +Patch608: ./kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -125,6 +126,7 @@ tar -z -x -v -f %{SOURCE19} %patch605 -p1 %patch606 -p1 %patch607 -p1 +%patch608 -p1 %ifarch ppc %define archdef ARCH=ppc From 475e33030b680143972d8de3273e648cae8372d8 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sun, 25 Apr 2021 17:05:42 +0800 Subject: [PATCH 033/454] Make dracut-squash required for kexec-tools This patch reverts commit "Make dracut-squash a weak dep". Although kexec-tools can work without dracut-squash, it is essential for kdump to run properly in cases [1][2] where minimal amount of memory consumption is expected. Thus dracut-squash is needed for it. [1] https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org/message/SJX7CW3WLOYSFI2YJKGTUGDBWSCMZXVZ/ [2] https://www.spinics.net/lists/systemd-devel/msg05864.html Signed-off-by: Tao Liu Acked-by: Kairui Song --- dracut-module-setup.sh | 3 --- kexec-tools.spec | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 066d0ce..5b810a0 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -35,9 +35,6 @@ depends() { modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1 fi done - - # check that the dracut squash module is available - [ -d "$(dracut_module_path squash)" ] || return 1 } if is_squash_available && ! is_fadump_capable; then diff --git a/kexec-tools.spec b/kexec-tools.spec index 1e6c99e..49cffce 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -61,7 +61,7 @@ Requires(postun): systemd-units Requires(pre): coreutils sed zlib Requires: dracut >= 050 Requires: dracut-network >= 050 -Recommends: dracut-squash >= 050 +Requires: dracut-squash >= 050 Requires: ethtool BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel From d0a301aa3a76e8006dfbfafb5b1e2f6437bd80af Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 28 Apr 2021 16:51:35 +0800 Subject: [PATCH 034/454] Release 2.0.21-9 Signed-off-by: Kairui Song --- kexec-tools.spec | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 49cffce..69a89d5 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.21 -Release: 8%{?dist} +Release: 9%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -367,6 +367,18 @@ done %endif %changelog +* Wed Apr 28 2021 Kairui Song - 2.0.21-9 +- Make dracut-squash required for kexec-tools +- Show write byte size in report messages +- Add shorthand --show-stats option to show report stats +- Add --dry-run option to prevent writing the dumpfile +- fadump: fix dump capture failure to root disk +- Write to `/var/lib/kdump` if $KDUMP_BOOTDIR not writable +- Drop dependency on ipcalc +- Implement IP netmask calculation to replace "ipcalc -m" +- Don't use die in dracut-module-setup.sh +- Don't iterate the whole /sys/devices just to find drm device + * Sat Apr 03 2021 Kairui Song - 2.0.21-8 - Update eppic to latest upstream snapshot - mkdumprd: prompt the user to install nfs-utils when mounting NFS fs failed From 6137956f79e8dc79bc1048efbe9bccbd66ac61e9 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 14 Apr 2021 13:41:19 +0800 Subject: [PATCH 035/454] kdumpctl: fix check_config error when kdump.conf is empty Kdump scirpt already have default values for core_collector, path in many other place. Empty kdump.conf still works. Fix this corner case and fix the error message. Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- kdumpctl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kdumpctl b/kdumpctl index b0846fa..009d259 100755 --- a/kdumpctl +++ b/kdumpctl @@ -237,12 +237,7 @@ restore_default_initrd() check_config() { local -A _opt_rec - while read config_opt config_val; do - if [ -z "$config_val" ]; then - derror "Invalid kdump config value for option $config_opt" - return 1 - fi - + while read -r config_opt config_val; do case "$config_opt" in dracut_args) if [[ $config_val == *--mount* ]]; then @@ -268,12 +263,20 @@ check_config() derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." return 1 ;; + '') + continue + ;; *) derror "Invalid kdump config option $config_opt" return 1 ;; esac + if [[ -z "$config_val" ]]; then + derror "Invalid kdump config value for option '$config_opt'" + return 1 + fi + if [ -n "${_opt_rec[$config_opt]}" ]; then if [ $config_opt == _target ]; then derror "More than one dump targets specified" From ee160bf04dfbe207fdec57adf05a98bf9ad8a83a Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 19 Apr 2021 23:00:10 +0800 Subject: [PATCH 036/454] Revert "Always set vm.zone_reclaim_mode = 3 in kdump kernel" This reverts commit 5633e8331866098c97e72e99f233a254fa479a4d. vm.zone_reclaim_mode may cause trashing on some machines. And after second thought, vm.zone_reclaim_mode is barely helpful for machines with high mem stress, so just revert it. Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- dracut-module-setup.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 5b810a0..eb8adfd 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -642,18 +642,16 @@ kdump_install_conf() { rm -f ${initdir}/tmp/$$-kdump.conf } -# Remove user custom configurations sysctl.conf & sysctl.d/* -# and apply some optimization for kdump -overwrite_sysctl_conf() { +# Default sysctl parameters should suffice for kdump kernel. +# Remove custom configurations sysctl.conf & sysctl.d/* +remove_sysctl_conf() { + # As custom configurations like vm.min_free_kbytes can lead # to OOM issues in kdump kernel, avoid them rm -f "${initdir}/etc/sysctl.conf" rm -rf "${initdir}/etc/sysctl.d" rm -rf "${initdir}/run/sysctl.d" rm -rf "${initdir}/usr/lib/sysctl.d" - - mkdir -p "${initdir}/etc/sysctl.d" - echo "vm.zone_reclaim_mode = 3" > "${initdir}/etc/sysctl.d/99-zone-reclaim.conf" } kdump_iscsi_get_rec_val() { @@ -944,7 +942,7 @@ kdump_install_systemd_conf() { install() { kdump_module_init kdump_install_conf - overwrite_sysctl_conf + remove_sysctl_conf if is_ssh_dump_target; then kdump_install_random_seed From ca05b754af74ab81525ff372f589ccfbc3ac81d9 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 10 May 2021 22:10:26 +0800 Subject: [PATCH 037/454] Fix incorrect file permissions of vmcore-dmesg-incomplete.txt vmcore-dmesg-incomplete.txt is generated by shell redirection, which taking the default umask value. When dmesg collector exits with non-zero, the file will exist and anyone can have access to it. This patch fixed the issue by chmod the file, making it accessible only to its owner. Signed-off-by: Tao Liu Acked-by: Kairui Song --- kdump-lib-initramfs.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 15bbd85..d0d124f 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -188,6 +188,9 @@ save_vmcore_dmesg_fs() { sync dinfo "saving vmcore-dmesg.txt complete" else + if [ -f ${_path}/vmcore-dmesg-incomplete.txt ]; then + chmod 600 ${_path}/vmcore-dmesg-incomplete.txt + fi derror "saving vmcore-dmesg.txt failed" fi } From 97ee5dc64c362cd9eef841378e3d95608f73c72d Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 6 May 2021 09:20:26 +0800 Subject: [PATCH 038/454] get kdump ifname once in kdump_install_net Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index eb8adfd..3657b35 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -477,7 +477,7 @@ kdump_get_remote_ip() # initramfs accessing giving destination # $1: destination host kdump_install_net() { - local _destaddr _srcaddr _route _netdev + local _destaddr _srcaddr _route _netdev kdumpnic local _static _proto _ip_conf _ip_opts _ifname_opts _destaddr=$(kdump_get_remote_ip $1) @@ -485,6 +485,7 @@ kdump_install_net() { _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") _netmac=$(kdump_get_mac_addr $_netdev) + kdumpnic=$(kdump_setup_ifname $_netdev) if [ "$(uname -m)" = "s390x" ]; then kdump_setup_znet $_netdev @@ -500,7 +501,7 @@ kdump_install_net() { fi _ip_conf="${initdir}/etc/cmdline.d/40ip.conf" - _ip_opts=" ip=${_static}$(kdump_setup_ifname $_netdev):${_proto}" + _ip_opts=" ip=${_static}$kdumpnic:${_proto}" # dracut doesn't allow duplicated configuration for same NIC, even they're exactly the same. # so we have to avoid adding duplicates @@ -520,7 +521,7 @@ kdump_install_net() { elif kdump_is_vlan "$_netdev"; then kdump_setup_vlan "$_netdev" else - _ifname_opts=" ifname=$(kdump_setup_ifname $_netdev):$_netmac" + _ifname_opts=" ifname=$kdumpnic:$_netmac" echo "$_ifname_opts" >> $_ip_conf fi @@ -540,8 +541,8 @@ kdump_install_net() { # gateway. if [ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ] && [ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then - echo "kdumpnic=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/60kdumpnic.conf - echo "bootdev=$(kdump_setup_ifname $_netdev)" > ${initdir}/etc/cmdline.d/70bootdev.conf + echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf + echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf fi } From 8a33ffffbcaab4d1baabed889c2a063649dcbab8 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 6 May 2021 09:20:27 +0800 Subject: [PATCH 039/454] rd.route should use the name from kdump_setup_ifname This fixes bz1854037 which happens because kexec-tools generates rd.route for eth0 instead of for kdump-eth0, 1. "rd.route=168.63.129.16:10.0.0.1:eth0 rd.route=169.254.169.254:10.0.0.1:eth0" is passed to the dracut cmdline by kexec-tools 2. In the 2rd kernel, dracut/modules.d/35network-manager/nm-config.sh calls /usr/libexec/nm-initrd-generator to generate two .nmconnection files based on the dracut cmdline, i.e. kdump-eth0.nmconnection and eth0.nmconnection, - /run/NetworkManager/system-connections/kdump-eth0.nmconnection [connection] id=kdump-eth0 uuid=3ef53b1b-3908-437e-a15f-cf1f3ea2678b type=ethernet autoconnect-retries=1 interface-name=kdump-eth0 multi-connect=1 permissions= wait-device-timeout=60000 [ethernet] mac-address-blacklist= [ipv4] address1=10.0.0.4/24,10.0.0.1 dhcp-timeout=90 dns=168.63.129.16; dns-search= may-fail=false method=manual [ipv6] addr-gen-mode=eui64 dhcp-timeout=90 dns-search= method=disabled [proxy] - /run/NetworkManager/system-connections/eth0.nmconnection [connection] id=eth0 uuid=f224dc22-2891-4d7b-8f66-745029df4b53 type=ethernet autoconnect-retries=1 interface-name=eth0 multi-connect=1 permissions= [ethernet] mac-address-blacklist= [ipv4] dhcp-timeout=90 dns=168.63.129.16; dns-search= method=auto route1=168.63.129.16/32,10.0.0.1 route2=169.254.169.254/32,10.0.0.1 [ipv6] addr-gen-mode=eui64 dhcp-timeout=90 dns-search= method=auto [proxy] 3. Since there's eth0.nmconnection, NetworkManager will try to get an IP for eth0 regardless of the fact it's a slave NIC and time out ``` $ ip link show 2: kdump-eth0: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 00:0d:3a:11:86:8b brd ff:ff:ff:ff:ff:ff 3: eth0: mtu 1500 qdisc mq master kdump-eth0 state UP mode DEFAULT group default qlen 1000 ``` Reported-by: Huijing Hei Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 3657b35..a8bfe53 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -232,7 +232,7 @@ cal_netmask_by_prefix() { #$2: srcaddr #if it use static ip echo it, or echo null kdump_static_ip() { - local _netdev="$1" _srcaddr="$2" _ipv6_flag + local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag local _netmask _gateway _ipaddr _target _nexthop _prefix _ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}") @@ -270,14 +270,14 @@ kdump_static_ip() { _target="[$_target]" _nexthop="[$_nexthop]" fi - echo "rd.route=$_target:$_nexthop:$_netdev" + echo "rd.route=$_target:$_nexthop:$kdumpnic" done >> ${initdir}/etc/cmdline.d/45route-static.conf - kdump_handle_mulitpath_route $_netdev $_srcaddr + kdump_handle_mulitpath_route $_netdev $_srcaddr $kdumpnic } kdump_handle_mulitpath_route() { - local _netdev="$1" _srcaddr="$2" _ipv6_flag + local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag local _target _nexthop _route _weight _max_weight _rule if is_ipv6_address $_srcaddr; then @@ -296,9 +296,9 @@ kdump_handle_mulitpath_route() { _nexthop=`echo "$_route" | cut -d ' ' -f3` _max_weight=$_weight if [ "x" != "x"$_ipv6_flag ]; then - _rule="rd.route=[$_target]:[$_nexthop]:$_netdev" + _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" else - _rule="rd.route=$_target:$_nexthop:$_netdev" + _rule="rd.route=$_target:$_nexthop:$kdumpnic" fi fi else @@ -491,7 +491,7 @@ kdump_install_net() { kdump_setup_znet $_netdev fi - _static=$(kdump_static_ip $_netdev $_srcaddr) + _static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) if [ -n "$_static" ]; then _proto=none elif is_ipv6_address $_srcaddr; then From dece041609e9139d0a227ca70f8f329feacce92f Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 11 May 2021 01:35:11 +0800 Subject: [PATCH 040/454] Release 2.0.22-1 Update kexec-tools to 2.0.22 Signed-off-by: Kairui Song --- kexec-tools.spec | 12 ++++++++++-- sources | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 69a89d5..264dd40 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,8 +4,8 @@ %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools -Version: 2.0.21 -Release: 9%{?dist} +Version: 2.0.22 +Release: 1%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -367,6 +367,14 @@ done %endif %changelog +* Tue May 11 2021 Kairui Song - 2.0.22-1 +- Update kexec-tools to 2.0.22 +- rd.route should use the name from kdump_setup_ifname +- get kdump ifname once in kdump_install_net +- Fix incorrect file permissions of vmcore-dmesg-incomplete.txt +- Revert "Always set vm.zone_reclaim_mode = 3 in kdump kernel" +- kdumpctl: fix check_config error when kdump.conf is empty + * Wed Apr 28 2021 Kairui Song - 2.0.21-9 - Make dracut-squash required for kexec-tools - Show write byte size in report messages diff --git a/sources b/sources index c0e1169..c3da2cf 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (makedumpfile-1.6.8.tar.gz) = 15e60688b06013bf86e339ec855774ea2c904d425371ea867101704ba0611c69da891eb3cc96f67eb10197d8c42d217ea28bf11bcaa93ddc2495cbf984c0b7ec -SHA512 (kexec-tools-2.0.21.tar.xz) = f487d2e243c2c4f29fbc9da7d06806f65210f717904655fc84d8d162b9c4614c3dd62e1bb47104a79f0dc2af04e462baf764fb309b5d7e6d287264cb48fd2a3e SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 +SHA512 (kexec-tools-2.0.22.tar.xz) = 7580860f272eee5af52139809f12961e5a5d3a65f4e191183ca9c845410425d25818945ac14ed04a60e6ce474dc2656fc6a14041177b0bf703f450820c7d6aba From c05d8a16a071303920ec840a6207f4db7fc26db4 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 13 May 2021 16:45:13 +0800 Subject: [PATCH 041/454] Update makedumpfile to 1.6.9 Signed-off-by: Kairui Song --- ...ove-duplicated-variable-declarations.patch | 98 --- ...-add-support-for-lockless-ringbuffer.patch | 587 ------------------ ...-use-committed-finalized-state-value.patch | 99 --- ...0.21-makedumpfile-Add-dry-run-option.patch | 177 ------ ...file-Add-shorthand-show-stats-option.patch | 107 ---- ...w-write-byte-size-in-report-messages.patch | 59 -- ...f-uts_namespace.name-offset-in-VMCOR.patch | 101 --- kexec-tools.spec | 16 +- sources | 2 +- 9 files changed, 3 insertions(+), 1243 deletions(-) delete mode 100644 kexec-tools-2.0.20-Remove-duplicated-variable-declarations.patch delete mode 100644 kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ringbuffer.patch delete mode 100644 kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch delete mode 100644 kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch delete mode 100644 kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch delete mode 100644 kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch delete mode 100644 kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch diff --git a/kexec-tools-2.0.20-Remove-duplicated-variable-declarations.patch b/kexec-tools-2.0.20-Remove-duplicated-variable-declarations.patch deleted file mode 100644 index 966f007..0000000 --- a/kexec-tools-2.0.20-Remove-duplicated-variable-declarations.patch +++ /dev/null @@ -1,98 +0,0 @@ -From 23daba8bb97ff4291447e54859ed759cfe07975e Mon Sep 17 00:00:00 2001 -From: Kairui Song -Date: Wed, 29 Jan 2020 10:48:27 +0800 -Subject: [PATCH] kexec-tools: Remove duplicated variable declarations - -When building kexec-tools for Fedora 32, following error is observed: - -/usr/bin/ld: kexec/arch/x86_64/kexec-bzImage64.o:(.bss+0x0): multiple definition of `bzImage_support_efi_boot'; -kexec/arch/i386/kexec-bzImage.o:(.bss+0x0): first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm/../../fs2dt.h:33: multiple definition of `my_debug'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/kexec/fs2dt.h:33: first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:68: multiple definition of `arm64_mem'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:68: first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:54: multiple definition of `initrd_size'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:54: first defined here - -/builddir/build/BUILD/kexec-tools-2.0.20/kexec/arch/arm64/kexec-arm64.h:53: multiple definition of `initrd_base'; -kexec/fs2dt.o:/builddir/build/BUILD/kexec-tools-2.0.20/././kexec/arch/arm64/kexec-arm64.h:53: first defined here - -And apparently, these variables are wrongly declared multiple times. So -remove duplicated declaration. - -Signed-off-by: Kairui Song ---- - kexec/arch/arm64/kexec-arm64.h | 6 +++--- - kexec/arch/ppc64/kexec-elf-ppc64.c | 2 -- - kexec/arch/x86_64/kexec-bzImage64.c | 1 - - kexec/fs2dt.h | 2 +- - 4 files changed, 4 insertions(+), 7 deletions(-) - -diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h -index 628de79..ed447ac 100644 ---- a/kexec/arch/arm64/kexec-arm64.h -+++ b/kexec/arch/arm64/kexec-arm64.h -@@ -50,8 +50,8 @@ int zImage_arm64_load(int argc, char **argv, const char *kernel_buf, - void zImage_arm64_usage(void); - - --off_t initrd_base; --off_t initrd_size; -+extern off_t initrd_base; -+extern off_t initrd_size; - - /** - * struct arm64_mem - Memory layout info. -@@ -65,7 +65,7 @@ struct arm64_mem { - }; - - #define arm64_mem_ngv UINT64_MAX --struct arm64_mem arm64_mem; -+extern struct arm64_mem arm64_mem; - - uint64_t get_phys_offset(void); - uint64_t get_vp_offset(void); -diff --git a/kexec/arch/ppc64/kexec-elf-ppc64.c b/kexec/arch/ppc64/kexec-elf-ppc64.c -index 3510b70..695b8b0 100644 ---- a/kexec/arch/ppc64/kexec-elf-ppc64.c -+++ b/kexec/arch/ppc64/kexec-elf-ppc64.c -@@ -44,8 +44,6 @@ - uint64_t initrd_base, initrd_size; - unsigned char reuse_initrd = 0; - const char *ramdisk; --/* Used for enabling printing message from purgatory code */ --int my_debug = 0; - - int elf_ppc64_probe(const char *buf, off_t len) - { -diff --git a/kexec/arch/x86_64/kexec-bzImage64.c b/kexec/arch/x86_64/kexec-bzImage64.c -index 8edb3e4..ba8dc48 100644 ---- a/kexec/arch/x86_64/kexec-bzImage64.c -+++ b/kexec/arch/x86_64/kexec-bzImage64.c -@@ -42,7 +42,6 @@ - #include - - static const int probe_debug = 0; --int bzImage_support_efi_boot; - - int bzImage64_probe(const char *buf, off_t len) - { -diff --git a/kexec/fs2dt.h b/kexec/fs2dt.h -index 7633273..fe24931 100644 ---- a/kexec/fs2dt.h -+++ b/kexec/fs2dt.h -@@ -30,7 +30,7 @@ extern struct bootblock bb[1]; - - /* Used for enabling printing message from purgatory code - * Only has implemented for PPC64 */ --int my_debug; -+extern int my_debug; - extern int dt_no_old_root; - - void reserve(unsigned long long where, unsigned long long length); --- -2.24.1 - diff --git a/kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ringbuffer.patch b/kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ringbuffer.patch deleted file mode 100644 index c445e76..0000000 --- a/kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ringbuffer.patch +++ /dev/null @@ -1,587 +0,0 @@ -From c617ec63339222f3a44d73e36677a9acc8954ccd Mon Sep 17 00:00:00 2001 -From: John Ogness -Date: Thu, 19 Nov 2020 02:41:21 +0000 -Subject: [PATCH 1/2] [PATCH 1/2] printk: add support for lockless ringbuffer - -* Required for kernel 5.10 - -Linux 5.10 introduces a new lockless ringbuffer. The new ringbuffer -is structured completely different to the previous iterations. -Add support for retrieving the ringbuffer from debug information -and/or using vmcoreinfo. The new ringbuffer is detected based on -the availability of the "prb" symbol. - -Signed-off-by: John Ogness -Signed-off-by: Kazuhito Hagio ---- - Makefile | 2 +- - dwarf_info.c | 36 ++++++++- - makedumpfile.c | 103 +++++++++++++++++++++++- - makedumpfile.h | 58 ++++++++++++++ - printk.c | 207 +++++++++++++++++++++++++++++++++++++++++++++++++ - 5 files changed, 399 insertions(+), 7 deletions(-) - create mode 100644 printk.c - -diff --git a/makedumpfile-1.6.8/Makefile b/makedumpfile-1.6.8/Makefile -index e5ac71a..cb6bd42 100644 ---- a/makedumpfile-1.6.8/Makefile -+++ b/makedumpfile-1.6.8/Makefile -@@ -45,7 +45,7 @@ CFLAGS_ARCH += -m32 - endif - - SRC_BASE = makedumpfile.c makedumpfile.h diskdump_mod.h sadump_mod.h sadump_info.h --SRC_PART = print_info.c dwarf_info.c elf_info.c erase_info.c sadump_info.c cache.c tools.c -+SRC_PART = print_info.c dwarf_info.c elf_info.c erase_info.c sadump_info.c cache.c tools.c printk.c - OBJ_PART=$(patsubst %.c,%.o,$(SRC_PART)) - SRC_ARCH = arch/arm.c arch/arm64.c arch/x86.c arch/x86_64.c arch/ia64.c arch/ppc64.c arch/s390x.c arch/ppc.c arch/sparc64.c - OBJ_ARCH=$(patsubst %.c,%.o,$(SRC_ARCH)) -diff --git a/makedumpfile-1.6.8/dwarf_info.c b/makedumpfile-1.6.8/dwarf_info.c -index e42a9f5..543588b 100644 ---- a/makedumpfile-1.6.8/dwarf_info.c -+++ b/makedumpfile-1.6.8/dwarf_info.c -@@ -614,6 +614,7 @@ search_structure(Dwarf_Die *die, int *found) - { - int tag; - const char *name; -+ Dwarf_Die die_type; - - /* - * If we get to here then we don't have any more -@@ -622,9 +623,31 @@ search_structure(Dwarf_Die *die, int *found) - do { - tag = dwarf_tag(die); - name = dwarf_diename(die); -- if ((tag != DW_TAG_structure_type) || (!name) -- || strcmp(name, dwarf_info.struct_name)) -+ if ((!name) || strcmp(name, dwarf_info.struct_name)) -+ continue; -+ -+ if (tag == DW_TAG_typedef) { -+ if (!get_die_type(die, &die_type)) { -+ ERRMSG("Can't get CU die of DW_AT_type.\n"); -+ break; -+ } -+ -+ /* Resolve typedefs of typedefs. */ -+ while ((tag = dwarf_tag(&die_type)) == DW_TAG_typedef) { -+ if (!get_die_type(&die_type, &die_type)) { -+ ERRMSG("Can't get CU die of DW_AT_type.\n"); -+ return; -+ } -+ } -+ -+ if (tag != DW_TAG_structure_type) -+ continue; -+ die = &die_type; -+ -+ } else if (tag != DW_TAG_structure_type) { - continue; -+ } -+ - /* - * Skip if DW_AT_byte_size is not included. - */ -@@ -740,6 +763,15 @@ search_typedef(Dwarf_Die *die, int *found) - ERRMSG("Can't get CU die of DW_AT_type.\n"); - break; - } -+ -+ /* Resolve typedefs of typedefs. */ -+ while ((tag = dwarf_tag(&die_type)) == DW_TAG_typedef) { -+ if (!get_die_type(&die_type, &die_type)) { -+ ERRMSG("Can't get CU die of DW_AT_type.\n"); -+ return; -+ } -+ } -+ - dwarf_info.struct_size = dwarf_bytesize(&die_type); - if (dwarf_info.struct_size <= 0) - continue; -diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c -index cdde040..061741f 100644 ---- a/makedumpfile-1.6.8/makedumpfile.c -+++ b/makedumpfile-1.6.8/makedumpfile.c -@@ -1555,6 +1555,7 @@ get_symbol_info(void) - SYMBOL_INIT(node_data, "node_data"); - SYMBOL_INIT(pgdat_list, "pgdat_list"); - SYMBOL_INIT(contig_page_data, "contig_page_data"); -+ SYMBOL_INIT(prb, "prb"); - SYMBOL_INIT(log_buf, "log_buf"); - SYMBOL_INIT(log_buf_len, "log_buf_len"); - SYMBOL_INIT(log_end, "log_end"); -@@ -1971,16 +1972,47 @@ get_structure_info(void) - OFFSET_INIT(elf64_phdr.p_memsz, "elf64_phdr", "p_memsz"); - - SIZE_INIT(printk_log, "printk_log"); -- if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) { -+ SIZE_INIT(printk_ringbuffer, "printk_ringbuffer"); -+ if ((SIZE(printk_ringbuffer) != NOT_FOUND_STRUCTURE)) { -+ info->flag_use_printk_ringbuffer = TRUE; -+ info->flag_use_printk_log = FALSE; -+ -+ OFFSET_INIT(printk_ringbuffer.desc_ring, "printk_ringbuffer", "desc_ring"); -+ OFFSET_INIT(printk_ringbuffer.text_data_ring, "printk_ringbuffer", "text_data_ring"); -+ -+ OFFSET_INIT(prb_desc_ring.count_bits, "prb_desc_ring", "count_bits"); -+ OFFSET_INIT(prb_desc_ring.descs, "prb_desc_ring", "descs"); -+ OFFSET_INIT(prb_desc_ring.infos, "prb_desc_ring", "infos"); -+ OFFSET_INIT(prb_desc_ring.head_id, "prb_desc_ring", "head_id"); -+ OFFSET_INIT(prb_desc_ring.tail_id, "prb_desc_ring", "tail_id"); -+ -+ SIZE_INIT(prb_desc, "prb_desc"); -+ OFFSET_INIT(prb_desc.state_var, "prb_desc", "state_var"); -+ OFFSET_INIT(prb_desc.text_blk_lpos, "prb_desc", "text_blk_lpos"); -+ -+ OFFSET_INIT(prb_data_blk_lpos.begin, "prb_data_blk_lpos", "begin"); -+ OFFSET_INIT(prb_data_blk_lpos.next, "prb_data_blk_lpos", "next"); -+ -+ OFFSET_INIT(prb_data_ring.size_bits, "prb_data_ring", "size_bits"); -+ OFFSET_INIT(prb_data_ring.data, "prb_data_ring", "data"); -+ -+ SIZE_INIT(printk_info, "printk_info"); -+ OFFSET_INIT(printk_info.ts_nsec, "printk_info", "ts_nsec"); -+ OFFSET_INIT(printk_info.text_len, "printk_info", "text_len"); -+ -+ OFFSET_INIT(atomic_long_t.counter, "atomic_long_t", "counter"); -+ } else if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) { - /* - * In kernel 3.11-rc4 the log structure name was renamed - * to "printk_log". - */ -+ info->flag_use_printk_ringbuffer = FALSE; - info->flag_use_printk_log = TRUE; - OFFSET_INIT(printk_log.ts_nsec, "printk_log", "ts_nsec"); - OFFSET_INIT(printk_log.len, "printk_log", "len"); - OFFSET_INIT(printk_log.text_len, "printk_log", "text_len"); - } else { -+ info->flag_use_printk_ringbuffer = FALSE; - info->flag_use_printk_log = FALSE; - SIZE_INIT(printk_log, "log"); - OFFSET_INIT(printk_log.ts_nsec, "log", "ts_nsec"); -@@ -2191,6 +2223,7 @@ write_vmcoreinfo_data(void) - WRITE_SYMBOL("node_data", node_data); - WRITE_SYMBOL("pgdat_list", pgdat_list); - WRITE_SYMBOL("contig_page_data", contig_page_data); -+ WRITE_SYMBOL("prb", prb); - WRITE_SYMBOL("log_buf", log_buf); - WRITE_SYMBOL("log_buf_len", log_buf_len); - WRITE_SYMBOL("log_end", log_end); -@@ -2222,7 +2255,11 @@ write_vmcoreinfo_data(void) - WRITE_STRUCTURE_SIZE("node_memblk_s", node_memblk_s); - WRITE_STRUCTURE_SIZE("nodemask_t", nodemask_t); - WRITE_STRUCTURE_SIZE("pageflags", pageflags); -- if (info->flag_use_printk_log) -+ if (info->flag_use_printk_ringbuffer) { -+ WRITE_STRUCTURE_SIZE("printk_ringbuffer", printk_ringbuffer); -+ WRITE_STRUCTURE_SIZE("prb_desc", prb_desc); -+ WRITE_STRUCTURE_SIZE("printk_info", printk_info); -+ } else if (info->flag_use_printk_log) - WRITE_STRUCTURE_SIZE("printk_log", printk_log); - else - WRITE_STRUCTURE_SIZE("log", printk_log); -@@ -2268,7 +2305,30 @@ write_vmcoreinfo_data(void) - WRITE_MEMBER_OFFSET("vm_struct.addr", vm_struct.addr); - WRITE_MEMBER_OFFSET("vmap_area.va_start", vmap_area.va_start); - WRITE_MEMBER_OFFSET("vmap_area.list", vmap_area.list); -- if (info->flag_use_printk_log) { -+ if (info->flag_use_printk_ringbuffer) { -+ WRITE_MEMBER_OFFSET("printk_ringbuffer.desc_ring", printk_ringbuffer.desc_ring); -+ WRITE_MEMBER_OFFSET("printk_ringbuffer.text_data_ring", printk_ringbuffer.text_data_ring); -+ -+ WRITE_MEMBER_OFFSET("prb_desc_ring.count_bits", prb_desc_ring.count_bits); -+ WRITE_MEMBER_OFFSET("prb_desc_ring.descs", prb_desc_ring.descs); -+ WRITE_MEMBER_OFFSET("prb_desc_ring.infos", prb_desc_ring.infos); -+ WRITE_MEMBER_OFFSET("prb_desc_ring.head_id", prb_desc_ring.head_id); -+ WRITE_MEMBER_OFFSET("prb_desc_ring.tail_id", prb_desc_ring.tail_id); -+ -+ WRITE_MEMBER_OFFSET("prb_desc.state_var", prb_desc.state_var); -+ WRITE_MEMBER_OFFSET("prb_desc.text_blk_lpos", prb_desc.text_blk_lpos); -+ -+ WRITE_MEMBER_OFFSET("prb_data_blk_lpos.begin", prb_data_blk_lpos.begin); -+ WRITE_MEMBER_OFFSET("prb_data_blk_lpos.next", prb_data_blk_lpos.next); -+ -+ WRITE_MEMBER_OFFSET("prb_data_ring.size_bits", prb_data_ring.size_bits); -+ WRITE_MEMBER_OFFSET("prb_data_ring.data", prb_data_ring.data); -+ -+ WRITE_MEMBER_OFFSET("printk_info.ts_nsec", printk_info.ts_nsec); -+ WRITE_MEMBER_OFFSET("printk_info.text_len", printk_info.text_len); -+ -+ WRITE_MEMBER_OFFSET("atomic_long_t.counter", atomic_long_t.counter); -+ } else if (info->flag_use_printk_log) { - WRITE_MEMBER_OFFSET("printk_log.ts_nsec", printk_log.ts_nsec); - WRITE_MEMBER_OFFSET("printk_log.len", printk_log.len); - WRITE_MEMBER_OFFSET("printk_log.text_len", printk_log.text_len); -@@ -2606,6 +2666,7 @@ read_vmcoreinfo(void) - READ_SYMBOL("node_data", node_data); - READ_SYMBOL("pgdat_list", pgdat_list); - READ_SYMBOL("contig_page_data", contig_page_data); -+ READ_SYMBOL("prb", prb); - READ_SYMBOL("log_buf", log_buf); - READ_SYMBOL("log_buf_len", log_buf_len); - READ_SYMBOL("log_end", log_end); -@@ -2684,12 +2745,43 @@ read_vmcoreinfo(void) - READ_MEMBER_OFFSET("cpu_spec.mmu_features", cpu_spec.mmu_features); - - READ_STRUCTURE_SIZE("printk_log", printk_log); -- if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) { -+ READ_STRUCTURE_SIZE("printk_ringbuffer", printk_ringbuffer); -+ if (SIZE(printk_ringbuffer) != NOT_FOUND_STRUCTURE) { -+ info->flag_use_printk_ringbuffer = TRUE; -+ info->flag_use_printk_log = FALSE; -+ -+ READ_MEMBER_OFFSET("printk_ringbuffer.desc_ring", printk_ringbuffer.desc_ring); -+ READ_MEMBER_OFFSET("printk_ringbuffer.text_data_ring", printk_ringbuffer.text_data_ring); -+ -+ READ_MEMBER_OFFSET("prb_desc_ring.count_bits", prb_desc_ring.count_bits); -+ READ_MEMBER_OFFSET("prb_desc_ring.descs", prb_desc_ring.descs); -+ READ_MEMBER_OFFSET("prb_desc_ring.infos", prb_desc_ring.infos); -+ READ_MEMBER_OFFSET("prb_desc_ring.head_id", prb_desc_ring.head_id); -+ READ_MEMBER_OFFSET("prb_desc_ring.tail_id", prb_desc_ring.tail_id); -+ -+ READ_STRUCTURE_SIZE("prb_desc", prb_desc); -+ READ_MEMBER_OFFSET("prb_desc.state_var", prb_desc.state_var); -+ READ_MEMBER_OFFSET("prb_desc.text_blk_lpos", prb_desc.text_blk_lpos); -+ -+ READ_MEMBER_OFFSET("prb_data_blk_lpos.begin", prb_data_blk_lpos.begin); -+ READ_MEMBER_OFFSET("prb_data_blk_lpos.next", prb_data_blk_lpos.next); -+ -+ READ_MEMBER_OFFSET("prb_data_ring.size_bits", prb_data_ring.size_bits); -+ READ_MEMBER_OFFSET("prb_data_ring.data", prb_data_ring.data); -+ -+ READ_STRUCTURE_SIZE("printk_info", printk_info); -+ READ_MEMBER_OFFSET("printk_info.ts_nsec", printk_info.ts_nsec); -+ READ_MEMBER_OFFSET("printk_info.text_len", printk_info.text_len); -+ -+ READ_MEMBER_OFFSET("atomic_long_t.counter", atomic_long_t.counter); -+ } else if (SIZE(printk_log) != NOT_FOUND_STRUCTURE) { -+ info->flag_use_printk_ringbuffer = FALSE; - info->flag_use_printk_log = TRUE; - READ_MEMBER_OFFSET("printk_log.ts_nsec", printk_log.ts_nsec); - READ_MEMBER_OFFSET("printk_log.len", printk_log.len); - READ_MEMBER_OFFSET("printk_log.text_len", printk_log.text_len); - } else { -+ info->flag_use_printk_ringbuffer = FALSE; - info->flag_use_printk_log = FALSE; - READ_STRUCTURE_SIZE("log", printk_log); - READ_MEMBER_OFFSET("log.ts_nsec", printk_log.ts_nsec); -@@ -5286,6 +5378,9 @@ dump_dmesg() - if (!initial()) - return FALSE; - -+ if ((SYMBOL(prb) != NOT_FOUND_SYMBOL)) -+ return dump_lockless_dmesg(); -+ - if ((SYMBOL(log_buf) == NOT_FOUND_SYMBOL) - || (SYMBOL(log_buf_len) == NOT_FOUND_SYMBOL)) { - ERRMSG("Can't find some symbols for log_buf.\n"); -diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h -index 698c054..47f7e79 100644 ---- a/makedumpfile-1.6.8/makedumpfile.h -+++ b/makedumpfile-1.6.8/makedumpfile.h -@@ -1317,6 +1317,7 @@ struct DumpInfo { - int flag_partial_dmesg; /* dmesg dump only from the last cleared index*/ - int flag_mem_usage; /*show the page number of memory in different use*/ - int flag_use_printk_log; /* did we read printk_log symbol name? */ -+ int flag_use_printk_ringbuffer; /* using lockless printk ringbuffer? */ - int flag_nospace; /* the flag of "No space on device" error */ - int flag_vmemmap; /* kernel supports vmemmap address space */ - int flag_excludevm; /* -e - excluding unused vmemmap pages */ -@@ -1602,6 +1603,7 @@ struct symbol_table { - unsigned long long node_data; - unsigned long long pgdat_list; - unsigned long long contig_page_data; -+ unsigned long long prb; - unsigned long long log_buf; - unsigned long long log_buf_len; - unsigned long long log_end; -@@ -1689,6 +1691,13 @@ struct size_table { - long nodemask_t; - long printk_log; - -+ /* -+ * for lockless printk ringbuffer -+ */ -+ long printk_ringbuffer; -+ long prb_desc; -+ long printk_info; -+ - /* - * for Xen extraction - */ -@@ -1864,6 +1873,52 @@ struct offset_table { - long text_len; - } printk_log; - -+ /* -+ * for lockless printk ringbuffer -+ */ -+ struct printk_ringbuffer_s { -+ long desc_ring; -+ long text_data_ring; -+ long fail; -+ } printk_ringbuffer; -+ -+ struct prb_desc_ring_s { -+ long count_bits; -+ long descs; -+ long infos; -+ long head_id; -+ long tail_id; -+ } prb_desc_ring; -+ -+ struct prb_desc_s { -+ long state_var; -+ long text_blk_lpos; -+ } prb_desc; -+ -+ struct prb_data_blk_lpos_s { -+ long begin; -+ long next; -+ } prb_data_blk_lpos; -+ -+ struct printk_info_s { -+ long seq; -+ long ts_nsec; -+ long text_len; -+ long caller_id; -+ long dev_info; -+ } printk_info; -+ -+ struct prb_data_ring_s { -+ long size_bits; -+ long data; -+ long head_lpos; -+ long tail_lpos; -+ } prb_data_ring; -+ -+ struct atomic_long_t_s { -+ long counter; -+ } atomic_long_t; -+ - /* - * symbols on ppc64 arch - */ -@@ -2390,4 +2445,7 @@ int hexadecimal(char *s, int count); - int decimal(char *s, int count); - int file_exists(char *file); - -+int open_dump_file(void); -+int dump_lockless_dmesg(void); -+ - #endif /* MAKEDUMPFILE_H */ -diff --git a/makedumpfile-1.6.8/printk.c b/makedumpfile-1.6.8/printk.c -new file mode 100644 -index 0000000..acffb6c ---- /dev/null -+++ b/makedumpfile-1.6.8/printk.c -@@ -0,0 +1,207 @@ -+#include "makedumpfile.h" -+#include -+ -+#define DESC_SV_BITS (sizeof(unsigned long) * 8) -+#define DESC_COMMITTED_MASK (1UL << (DESC_SV_BITS - 1)) -+#define DESC_REUSE_MASK (1UL << (DESC_SV_BITS - 2)) -+#define DESC_FLAGS_MASK (DESC_COMMITTED_MASK | DESC_REUSE_MASK) -+#define DESC_ID_MASK (~DESC_FLAGS_MASK) -+ -+/* convenience struct for passing many values to helper functions */ -+struct prb_map { -+ char *prb; -+ -+ char *desc_ring; -+ unsigned long desc_ring_count; -+ char *descs; -+ char *infos; -+ -+ char *text_data_ring; -+ unsigned long text_data_ring_size; -+ char *text_data; -+}; -+ -+static void -+dump_record(struct prb_map *m, unsigned long id) -+{ -+ unsigned long long ts_nsec; -+ unsigned long state_var; -+ unsigned short text_len; -+ unsigned long begin; -+ unsigned long next; -+ char buf[BUFSIZE]; -+ ulonglong nanos; -+ int indent_len; -+ int buf_need; -+ char *bufp; -+ char *text; -+ char *desc; -+ char *inf; -+ ulong rem; -+ char *p; -+ int i; -+ -+ desc = m->descs + ((id % m->desc_ring_count) * SIZE(prb_desc)); -+ -+ /* skip non-committed record */ -+ state_var = ULONG(desc + OFFSET(prb_desc.state_var) + OFFSET(atomic_long_t.counter)); -+ if ((state_var & DESC_FLAGS_MASK) != DESC_COMMITTED_MASK) -+ return; -+ -+ begin = ULONG(desc + OFFSET(prb_desc.text_blk_lpos) + OFFSET(prb_data_blk_lpos.begin)) % -+ m->text_data_ring_size; -+ next = ULONG(desc + OFFSET(prb_desc.text_blk_lpos) + OFFSET(prb_data_blk_lpos.next)) % -+ m->text_data_ring_size; -+ -+ /* skip data-less text blocks */ -+ if (begin == next) -+ return; -+ -+ inf = m->infos + ((id % m->desc_ring_count) * SIZE(printk_info)); -+ -+ text_len = USHORT(inf + OFFSET(printk_info.text_len)); -+ -+ /* handle wrapping data block */ -+ if (begin > next) -+ begin = 0; -+ -+ /* skip over descriptor ID */ -+ begin += sizeof(unsigned long); -+ -+ /* handle truncated messages */ -+ if (next - begin < text_len) -+ text_len = next - begin; -+ -+ text = m->text_data + begin; -+ -+ ts_nsec = ULONGLONG(inf + OFFSET(printk_info.ts_nsec)); -+ nanos = (ulonglong)ts_nsec / (ulonglong)1000000000; -+ rem = (ulonglong)ts_nsec % (ulonglong)1000000000; -+ -+ bufp = buf; -+ bufp += sprintf(buf, "[%5lld.%06ld] ", nanos, rem/1000); -+ indent_len = strlen(buf); -+ -+ /* How much buffer space is needed in the worst case */ -+ buf_need = MAX(sizeof("\\xXX\n"), sizeof("\n") + indent_len); -+ -+ for (i = 0, p = text; i < text_len; i++, p++) { -+ if (bufp - buf >= sizeof(buf) - buf_need) { -+ if (write(info->fd_dumpfile, buf, bufp - buf) < 0) -+ return; -+ bufp = buf; -+ } -+ -+ if (*p == '\n') -+ bufp += sprintf(bufp, "\n%-*s", indent_len, ""); -+ else if (isprint(*p) || isspace(*p)) -+ *bufp++ = *p; -+ else -+ bufp += sprintf(bufp, "\\x%02x", *p); -+ } -+ -+ *bufp++ = '\n'; -+ -+ write(info->fd_dumpfile, buf, bufp - buf); -+} -+ -+int -+dump_lockless_dmesg(void) -+{ -+ unsigned long head_id; -+ unsigned long tail_id; -+ unsigned long kaddr; -+ unsigned long id; -+ struct prb_map m; -+ int ret = FALSE; -+ -+ /* setup printk_ringbuffer */ -+ if (!readmem(VADDR, SYMBOL(prb), &kaddr, sizeof(kaddr))) { -+ ERRMSG("Can't get the prb address.\n"); -+ return ret; -+ } -+ -+ m.prb = malloc(SIZE(printk_ringbuffer)); -+ if (!m.prb) { -+ ERRMSG("Can't allocate memory for prb.\n"); -+ return ret; -+ } -+ if (!readmem(VADDR, kaddr, m.prb, SIZE(printk_ringbuffer))) { -+ ERRMSG("Can't get prb.\n"); -+ goto out_prb; -+ } -+ -+ /* setup descriptor ring */ -+ m.desc_ring = m.prb + OFFSET(printk_ringbuffer.desc_ring); -+ m.desc_ring_count = 1 << UINT(m.desc_ring + OFFSET(prb_desc_ring.count_bits)); -+ -+ kaddr = ULONG(m.desc_ring + OFFSET(prb_desc_ring.descs)); -+ m.descs = malloc(SIZE(prb_desc) * m.desc_ring_count); -+ if (!m.descs) { -+ ERRMSG("Can't allocate memory for prb.desc_ring.descs.\n"); -+ goto out_prb; -+ } -+ if (!readmem(VADDR, kaddr, m.descs, -+ SIZE(prb_desc) * m.desc_ring_count)) { -+ ERRMSG("Can't get prb.desc_ring.descs.\n"); -+ goto out_descs; -+ } -+ -+ kaddr = ULONG(m.desc_ring + OFFSET(prb_desc_ring.infos)); -+ m.infos = malloc(SIZE(printk_info) * m.desc_ring_count); -+ if (!m.infos) { -+ ERRMSG("Can't allocate memory for prb.desc_ring.infos.\n"); -+ goto out_descs; -+ } -+ if (!readmem(VADDR, kaddr, m.infos, SIZE(printk_info) * m.desc_ring_count)) { -+ ERRMSG("Can't get prb.desc_ring.infos.\n"); -+ goto out_infos; -+ } -+ -+ /* setup text data ring */ -+ m.text_data_ring = m.prb + OFFSET(printk_ringbuffer.text_data_ring); -+ m.text_data_ring_size = 1 << UINT(m.text_data_ring + OFFSET(prb_data_ring.size_bits)); -+ -+ kaddr = ULONG(m.text_data_ring + OFFSET(prb_data_ring.data)); -+ m.text_data = malloc(m.text_data_ring_size); -+ if (!m.text_data) { -+ ERRMSG("Can't allocate memory for prb.text_data_ring.data.\n"); -+ goto out_infos; -+ } -+ if (!readmem(VADDR, kaddr, m.text_data, m.text_data_ring_size)) { -+ ERRMSG("Can't get prb.text_data_ring.\n"); -+ goto out_text_data; -+ } -+ -+ /* ready to go */ -+ -+ tail_id = ULONG(m.desc_ring + OFFSET(prb_desc_ring.tail_id) + -+ OFFSET(atomic_long_t.counter)); -+ head_id = ULONG(m.desc_ring + OFFSET(prb_desc_ring.head_id) + -+ OFFSET(atomic_long_t.counter)); -+ -+ if (!open_dump_file()) { -+ ERRMSG("Can't open output file.\n"); -+ goto out_text_data; -+ } -+ -+ for (id = tail_id; id != head_id; id = (id + 1) & DESC_ID_MASK) -+ dump_record(&m, id); -+ -+ /* dump head record */ -+ dump_record(&m, id); -+ -+ if (!close_files_for_creating_dumpfile()) -+ goto out_text_data; -+ -+ ret = TRUE; -+out_text_data: -+ free(m.text_data); -+out_infos: -+ free(m.infos); -+out_descs: -+ free(m.descs); -+out_prb: -+ free(m.prb); -+ return ret; -+} --- -2.29.2 - diff --git a/kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch b/kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch deleted file mode 100644 index 8ec27bf..0000000 --- a/kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch +++ /dev/null @@ -1,99 +0,0 @@ -From 44b073b7ec467aee0d7de381d455b8ace1199184 Mon Sep 17 00:00:00 2001 -From: John Ogness -Date: Wed, 25 Nov 2020 10:10:31 +0106 -Subject: [PATCH 2/2] [PATCH 2/2] printk: use committed/finalized state values - -* Required for kernel 5.10 - -The ringbuffer entries use 2 state values (committed and finalized) -rather than a single flag to represent being available for reading. -Copy the definitions and state lookup function directly from the -kernel source and use the new states. - -Signed-off-by: John Ogness ---- - printk.c | 48 +++++++++++++++++++++++++++++++++++++++++------- - 1 file changed, 41 insertions(+), 7 deletions(-) - -diff --git a/makedumpfile-1.6.8/printk.c b/makedumpfile-1.6.8/printk.c -index acffb6c..2af8562 100644 ---- a/makedumpfile-1.6.8/printk.c -+++ b/makedumpfile-1.6.8/printk.c -@@ -1,12 +1,6 @@ - #include "makedumpfile.h" - #include - --#define DESC_SV_BITS (sizeof(unsigned long) * 8) --#define DESC_COMMITTED_MASK (1UL << (DESC_SV_BITS - 1)) --#define DESC_REUSE_MASK (1UL << (DESC_SV_BITS - 2)) --#define DESC_FLAGS_MASK (DESC_COMMITTED_MASK | DESC_REUSE_MASK) --#define DESC_ID_MASK (~DESC_FLAGS_MASK) -- - /* convenience struct for passing many values to helper functions */ - struct prb_map { - char *prb; -@@ -21,12 +15,51 @@ struct prb_map { - char *text_data; - }; - -+/* -+ * desc_state and DESC_* definitions taken from kernel source: -+ * -+ * kernel/printk/printk_ringbuffer.h -+ */ -+ -+/* The possible responses of a descriptor state-query. */ -+enum desc_state { -+ desc_miss = -1, /* ID mismatch (pseudo state) */ -+ desc_reserved = 0x0, /* reserved, in use by writer */ -+ desc_committed = 0x1, /* committed by writer, could get reopened */ -+ desc_finalized = 0x2, /* committed, no further modification allowed */ -+ desc_reusable = 0x3, /* free, not yet used by any writer */ -+}; -+ -+#define DESC_SV_BITS (sizeof(unsigned long) * 8) -+#define DESC_FLAGS_SHIFT (DESC_SV_BITS - 2) -+#define DESC_FLAGS_MASK (3UL << DESC_FLAGS_SHIFT) -+#define DESC_STATE(sv) (3UL & (sv >> DESC_FLAGS_SHIFT)) -+#define DESC_ID_MASK (~DESC_FLAGS_MASK) -+#define DESC_ID(sv) ((sv) & DESC_ID_MASK) -+ -+/* -+ * get_desc_state() taken from kernel source: -+ * -+ * kernel/printk/printk_ringbuffer.c -+ */ -+ -+/* Query the state of a descriptor. */ -+static enum desc_state get_desc_state(unsigned long id, -+ unsigned long state_val) -+{ -+ if (id != DESC_ID(state_val)) -+ return desc_miss; -+ -+ return DESC_STATE(state_val); -+} -+ - static void - dump_record(struct prb_map *m, unsigned long id) - { - unsigned long long ts_nsec; - unsigned long state_var; - unsigned short text_len; -+ enum desc_state state; - unsigned long begin; - unsigned long next; - char buf[BUFSIZE]; -@@ -45,7 +78,8 @@ dump_record(struct prb_map *m, unsigned long id) - - /* skip non-committed record */ - state_var = ULONG(desc + OFFSET(prb_desc.state_var) + OFFSET(atomic_long_t.counter)); -- if ((state_var & DESC_FLAGS_MASK) != DESC_COMMITTED_MASK) -+ state = get_desc_state(id, state_var); -+ if (state != desc_committed && state != desc_finalized) - return; - - begin = ULONG(desc + OFFSET(prb_desc.text_blk_lpos) + OFFSET(prb_data_blk_lpos.begin)) % --- -2.29.2 - diff --git a/kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch b/kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch deleted file mode 100644 index ffe8a39..0000000 --- a/kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch +++ /dev/null @@ -1,177 +0,0 @@ -From 3422e1d6bc3511c5af9cb05ba74ad97dd93ffd7f Mon Sep 17 00:00:00 2001 -From: Julien Thierry -Date: Tue, 24 Nov 2020 10:45:24 +0000 -Subject: [PATCH 02/12] [PATCH 1/2] Add --dry-run option to prevent writing the - dumpfile - -Add a --dry-run option to run all operations without writing the -dump to the output file. - -Signed-off-by: Julien Thierry -Signed-off-by: Kazuhito Hagio ---- - makedumpfile.8 | 6 ++++++ - makedumpfile.c | 37 ++++++++++++++++++++++++++++++------- - makedumpfile.h | 2 ++ - print_info.c | 3 +++ - 4 files changed, 41 insertions(+), 7 deletions(-) - -diff --git a/makedumpfile-1.6.8/makedumpfile.8 b/makedumpfile-1.6.8/makedumpfile.8 -index b68a7e3..5e902cd 100644 ---- a/makedumpfile-1.6.8/makedumpfile.8 -+++ b/makedumpfile-1.6.8/makedumpfile.8 -@@ -637,6 +637,12 @@ Show the version of makedumpfile. - Only check whether the command-line parameters are valid or not, and exit. - Preferable to be given as the first parameter. - -+.TP -+\fB\-\-dry-run\fR -+Do not write the output dump file while still performing operations specified -+by other options. -+This option cannot be used with the --dump-dmesg, --reassemble and -g options. -+ - .SH ENVIRONMENT VARIABLES - - .TP 8 -diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c -index ecd63fa..8c80c49 100644 ---- a/makedumpfile-1.6.8/makedumpfile.c -+++ b/makedumpfile-1.6.8/makedumpfile.c -@@ -1372,6 +1372,8 @@ open_dump_file(void) - if (info->flag_flatten) { - fd = STDOUT_FILENO; - info->name_dumpfile = filename_stdout; -+ } else if (info->flag_dry_run) { -+ fd = -1; - } else if ((fd = open(info->name_dumpfile, open_flags, - S_IRUSR|S_IWUSR)) < 0) { - ERRMSG("Can't open the dump file(%s). %s\n", -@@ -4711,6 +4713,9 @@ write_and_check_space(int fd, void *buf, size_t buf_size, char *file_name) - { - int status, written_size = 0; - -+ if (info->flag_dry_run) -+ return TRUE; -+ - while (written_size < buf_size) { - status = write(fd, buf + written_size, - buf_size - written_size); -@@ -4748,13 +4753,12 @@ write_buffer(int fd, off_t offset, void *buf, size_t buf_size, char *file_name) - } - if (!write_and_check_space(fd, &fdh, sizeof(fdh), file_name)) - return FALSE; -- } else { -- if (lseek(fd, offset, SEEK_SET) == failed) { -- ERRMSG("Can't seek the dump file(%s). %s\n", -- file_name, strerror(errno)); -- return FALSE; -- } -+ } else if (!info->flag_dry_run && -+ lseek(fd, offset, SEEK_SET) == failed) { -+ ERRMSG("Can't seek the dump file(%s). %s\n", file_name, strerror(errno)); -+ return FALSE; - } -+ - if (!write_and_check_space(fd, buf, buf_size, file_name)) - return FALSE; - -@@ -9112,7 +9116,7 @@ close_dump_memory(void) - void - close_dump_file(void) - { -- if (info->flag_flatten) -+ if (info->flag_flatten || info->flag_dry_run) - return; - - if (close(info->fd_dumpfile) < 0) -@@ -10985,6 +10989,11 @@ check_param_for_generating_vmcoreinfo(int argc, char *argv[]) - - return FALSE; - -+ if (info->flag_dry_run) { -+ MSG("--dry-run cannot be used with -g.\n"); -+ return FALSE; -+ } -+ - return TRUE; - } - -@@ -11029,6 +11038,11 @@ check_param_for_reassembling_dumpfile(int argc, char *argv[]) - || info->flag_exclude_xen_dom || info->flag_split) - return FALSE; - -+ if (info->flag_dry_run) { -+ MSG("--dry-run cannot be used with --reassemble.\n"); -+ return FALSE; -+ } -+ - if ((info->splitting_info - = malloc(sizeof(struct splitting_info) * info->num_dumpfile)) - == NULL) { -@@ -11057,6 +11071,11 @@ check_param_for_creating_dumpfile(int argc, char *argv[]) - || (info->flag_read_vmcoreinfo && info->name_xen_syms)) - return FALSE; - -+ if (info->flag_dry_run && info->flag_dmesg) { -+ MSG("--dry-run cannot be used with --dump-dmesg.\n"); -+ return FALSE; -+ } -+ - if (info->flag_flatten && info->flag_split) - return FALSE; - -@@ -11520,6 +11539,7 @@ static struct option longopts[] = { - {"work-dir", required_argument, NULL, OPT_WORKING_DIR}, - {"num-threads", required_argument, NULL, OPT_NUM_THREADS}, - {"check-params", no_argument, NULL, OPT_CHECK_PARAMS}, -+ {"dry-run", no_argument, NULL, OPT_DRY_RUN}, - {0, 0, 0, 0} - }; - -@@ -11686,6 +11706,9 @@ main(int argc, char *argv[]) - info->flag_check_params = TRUE; - message_level = DEFAULT_MSG_LEVEL; - break; -+ case OPT_DRY_RUN: -+ info->flag_dry_run = TRUE; -+ break; - case '?': - MSG("Commandline parameter is invalid.\n"); - MSG("Try `makedumpfile --help' for more information.\n"); -diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h -index 5f50080..4c4222c 100644 ---- a/makedumpfile-1.6.8/makedumpfile.h -+++ b/makedumpfile-1.6.8/makedumpfile.h -@@ -1322,6 +1322,7 @@ struct DumpInfo { - int flag_vmemmap; /* kernel supports vmemmap address space */ - int flag_excludevm; /* -e - excluding unused vmemmap pages */ - int flag_use_count; /* _refcount is named _count in struct page */ -+ int flag_dry_run; /* do not create a vmcore file */ - unsigned long vaddr_for_vtop; /* virtual address for debugging */ - long page_size; /* size of page */ - long page_shift; -@@ -2425,6 +2426,7 @@ struct elf_prstatus { - #define OPT_NUM_THREADS OPT_START+16 - #define OPT_PARTIAL_DMESG OPT_START+17 - #define OPT_CHECK_PARAMS OPT_START+18 -+#define OPT_DRY_RUN OPT_START+19 - - /* - * Function Prototype. -diff --git a/makedumpfile-1.6.8/print_info.c b/makedumpfile-1.6.8/print_info.c -index e0c38b4..d2b0cb7 100644 ---- a/makedumpfile-1.6.8/print_info.c -+++ b/makedumpfile-1.6.8/print_info.c -@@ -308,6 +308,9 @@ print_usage(void) - MSG(" the crashkernel range, then calculates the page number of different kind per\n"); - MSG(" vmcoreinfo. So currently /proc/kcore need be specified explicitly.\n"); - MSG("\n"); -+ MSG(" [--dry-run]:\n"); -+ MSG(" This option runs makedumpfile without writting output dump file.\n"); -+ MSG("\n"); - MSG(" [-D]:\n"); - MSG(" Print debugging message.\n"); - MSG("\n"); --- -2.29.2 - diff --git a/kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch b/kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch deleted file mode 100644 index 4f259ab..0000000 --- a/kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch +++ /dev/null @@ -1,107 +0,0 @@ -From 6f3e75a558ed50d6ff0b42e3f61c099b2005b7bb Mon Sep 17 00:00:00 2001 -From: Julien Thierry -Date: Tue, 24 Nov 2020 10:45:25 +0000 -Subject: [PATCH 03/12] [PATCH 2/2] Add shorthand --show-stats option to show - report stats - -Provide shorthand --show-stats option to enable report messages -without needing to set a particular value for message-level. - -Signed-off-by: Julien Thierry -Signed-off-by: Kazuhito Hagio ---- - makedumpfile.8 | 5 +++++ - makedumpfile.c | 9 ++++++++- - makedumpfile.h | 1 + - print_info.c | 7 ++++++- - 4 files changed, 20 insertions(+), 2 deletions(-) - -diff --git a/makedumpfile-1.6.8/makedumpfile.8 b/makedumpfile-1.6.8/makedumpfile.8 -index 5e902cd..dcca2dd 100644 ---- a/makedumpfile-1.6.8/makedumpfile.8 -+++ b/makedumpfile-1.6.8/makedumpfile.8 -@@ -643,6 +643,11 @@ Do not write the output dump file while still performing operations specified - by other options. - This option cannot be used with the --dump-dmesg, --reassemble and -g options. - -+.TP -+\fB\-\-show-stats\fR -+Display report messages. This is an alternative to enabling bit 4 in the level -+provided to --message-level. -+ - .SH ENVIRONMENT VARIABLES - - .TP 8 -diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c -index 8c80c49..ba0003a 100644 ---- a/makedumpfile-1.6.8/makedumpfile.c -+++ b/makedumpfile-1.6.8/makedumpfile.c -@@ -11540,13 +11540,14 @@ static struct option longopts[] = { - {"num-threads", required_argument, NULL, OPT_NUM_THREADS}, - {"check-params", no_argument, NULL, OPT_CHECK_PARAMS}, - {"dry-run", no_argument, NULL, OPT_DRY_RUN}, -+ {"show-stats", no_argument, NULL, OPT_SHOW_STATS}, - {0, 0, 0, 0} - }; - - int - main(int argc, char *argv[]) - { -- int i, opt, flag_debug = FALSE; -+ int i, opt, flag_debug = FALSE, flag_show_stats = FALSE; - - if ((info = calloc(1, sizeof(struct DumpInfo))) == NULL) { - ERRMSG("Can't allocate memory for the pagedesc cache. %s.\n", -@@ -11709,6 +11710,9 @@ main(int argc, char *argv[]) - case OPT_DRY_RUN: - info->flag_dry_run = TRUE; - break; -+ case OPT_SHOW_STATS: -+ flag_show_stats = TRUE; -+ break; - case '?': - MSG("Commandline parameter is invalid.\n"); - MSG("Try `makedumpfile --help' for more information.\n"); -@@ -11718,6 +11722,9 @@ main(int argc, char *argv[]) - if (flag_debug) - message_level |= ML_PRINT_DEBUG_MSG; - -+ if (flag_show_stats) -+ message_level |= ML_PRINT_REPORT_MSG; -+ - if (info->flag_check_params) - /* suppress debugging messages */ - message_level = DEFAULT_MSG_LEVEL; -diff --git a/makedumpfile-1.6.8/makedumpfile.h b/makedumpfile-1.6.8/makedumpfile.h -index 4c4222c..2fcb62e 100644 ---- a/makedumpfile-1.6.8/makedumpfile.h -+++ b/makedumpfile-1.6.8/makedumpfile.h -@@ -2427,6 +2427,7 @@ struct elf_prstatus { - #define OPT_PARTIAL_DMESG OPT_START+17 - #define OPT_CHECK_PARAMS OPT_START+18 - #define OPT_DRY_RUN OPT_START+19 -+#define OPT_SHOW_STATS OPT_START+20 - - /* - * Function Prototype. -diff --git a/makedumpfile-1.6.8/print_info.c b/makedumpfile-1.6.8/print_info.c -index d2b0cb7..ad4184e 100644 ---- a/makedumpfile-1.6.8/print_info.c -+++ b/makedumpfile-1.6.8/print_info.c -@@ -309,7 +309,12 @@ print_usage(void) - MSG(" vmcoreinfo. So currently /proc/kcore need be specified explicitly.\n"); - MSG("\n"); - MSG(" [--dry-run]:\n"); -- MSG(" This option runs makedumpfile without writting output dump file.\n"); -+ MSG(" Do not write the output dump file while still performing operations specified\n"); -+ MSG(" by other options. This option cannot be used with --dump-dmesg, --reassemble\n"); -+ MSG(" and -g options.\n"); -+ MSG("\n"); -+ MSG(" [--show-stats]:\n"); -+ MSG(" Set message-level to print report messages\n"); - MSG("\n"); - MSG(" [-D]:\n"); - MSG(" Print debugging message.\n"); --- -2.29.2 - diff --git a/kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch b/kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch deleted file mode 100644 index be89b54..0000000 --- a/kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 0ef2ca6c9fa2f61f217a4bf5d7fd70f24e12b2eb Mon Sep 17 00:00:00 2001 -From: Kazuhito Hagio -Date: Thu, 4 Feb 2021 16:29:06 +0900 -Subject: [PATCH 09/12] [PATCH] Show write byte size in report messages - -Show write byte size in report messages. This value can be different -from the size of the actual file because of some holes on dumpfile -data structure. - - $ makedumpfile --show-stats -l -d 1 vmcore dump.ld1 - ... - Total pages : 0x0000000000080000 - Write bytes : 377686445 - ... - # ls -l dump.ld1 - -rw------- 1 root root 377691573 Feb 4 16:28 dump.ld1 - -Note that this value should not be used with /proc/kcore to determine -how much disk space is needed for crash dump, because the real memory -usage when a crash occurs can vary widely. - -Signed-off-by: Kazuhito Hagio ---- - makedumpfile.c | 5 +++++ - 1 file changed, 5 insertions(+) - -diff --git a/makedumpfile-1.6.8/makedumpfile.c b/makedumpfile-1.6.8/makedumpfile.c -index fcd766b..894c88e 100644 ---- a/makedumpfile-1.6.8/makedumpfile.c -+++ b/makedumpfile-1.6.8/makedumpfile.c -@@ -48,6 +48,8 @@ char filename_stdout[] = FILENAME_STDOUT; - static unsigned long long cache_hit; - static unsigned long long cache_miss; - -+static unsigned long long write_bytes; -+ - static void first_cycle(mdf_pfn_t start, mdf_pfn_t max, struct cycle *cycle) - { - cycle->start_pfn = round(start, info->pfn_cyclic); -@@ -4715,6 +4717,8 @@ write_and_check_space(int fd, void *buf, size_t buf_size, char *file_name) - { - int status, written_size = 0; - -+ write_bytes += buf_size; -+ - if (info->flag_dry_run) - return TRUE; - -@@ -10002,6 +10006,7 @@ print_report(void) - REPORT_MSG("Memory Hole : 0x%016llx\n", pfn_memhole); - REPORT_MSG("--------------------------------------------------\n"); - REPORT_MSG("Total pages : 0x%016llx\n", info->max_mapnr); -+ REPORT_MSG("Write bytes : %llu\n", write_bytes); - REPORT_MSG("\n"); - REPORT_MSG("Cache hit: %lld, miss: %lld", cache_hit, cache_miss); - if (cache_hit + cache_miss) --- -2.29.2 - diff --git a/kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch b/kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch deleted file mode 100644 index 0c29723..0000000 --- a/kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch +++ /dev/null @@ -1,101 +0,0 @@ -From 54aec3878b3f91341e6bc735eda158cca5c54ec9 Mon Sep 17 00:00:00 2001 -From: Alexander Egorenkov -Date: Fri, 18 Sep 2020 13:55:56 +0200 -Subject: [PATCH] [PATCH] make use of 'uts_namespace.name' offset in VMCOREINFO - -* Required for kernel 5.11 - -The offset of the field 'init_uts_ns.name' has changed since -kernel commit 9a56493f6942 ("uts: Use generic ns_common::count"). -Make use of the offset 'uts_namespace.name' if available in -VMCOREINFO. - -Signed-off-by: Alexander Egorenkov ---- - makedumpfile.c | 17 +++++++++++++++-- - makedumpfile.h | 6 ++++++ - 2 files changed, 21 insertions(+), 2 deletions(-) - -diff --git a/makedumpfile.c b/makedumpfile.c -index 061741f..ecd63fa 100644 ---- a/makedumpfile-1.6.8/makedumpfile.c -+++ b/makedumpfile-1.6.8/makedumpfile.c -@@ -1159,7 +1159,10 @@ check_release(void) - if (SYMBOL(system_utsname) != NOT_FOUND_SYMBOL) { - utsname = SYMBOL(system_utsname); - } else if (SYMBOL(init_uts_ns) != NOT_FOUND_SYMBOL) { -- utsname = SYMBOL(init_uts_ns) + sizeof(int); -+ if (OFFSET(uts_namespace.name) != NOT_FOUND_STRUCTURE) -+ utsname = SYMBOL(init_uts_ns) + OFFSET(uts_namespace.name); -+ else -+ utsname = SYMBOL(init_uts_ns) + sizeof(int); - } else { - ERRMSG("Can't get the symbol of system_utsname.\n"); - return FALSE; -@@ -2040,6 +2043,11 @@ get_structure_info(void) - SIZE_INIT(cpu_spec, "cpu_spec"); - OFFSET_INIT(cpu_spec.mmu_features, "cpu_spec", "mmu_features"); - -+ /* -+ * Get offsets of the uts_namespace's members. -+ */ -+ OFFSET_INIT(uts_namespace.name, "uts_namespace", "name"); -+ - return TRUE; - } - -@@ -2109,7 +2117,10 @@ get_str_osrelease_from_vmlinux(void) - if (SYMBOL(system_utsname) != NOT_FOUND_SYMBOL) { - utsname = SYMBOL(system_utsname); - } else if (SYMBOL(init_uts_ns) != NOT_FOUND_SYMBOL) { -- utsname = SYMBOL(init_uts_ns) + sizeof(int); -+ if (OFFSET(uts_namespace.name) != NOT_FOUND_STRUCTURE) -+ utsname = SYMBOL(init_uts_ns) + OFFSET(uts_namespace.name); -+ else -+ utsname = SYMBOL(init_uts_ns) + sizeof(int); - } else { - ERRMSG("Can't get the symbol of system_utsname.\n"); - return FALSE; -@@ -2344,6 +2355,7 @@ write_vmcoreinfo_data(void) - WRITE_MEMBER_OFFSET("vmemmap_backing.list", vmemmap_backing.list); - WRITE_MEMBER_OFFSET("mmu_psize_def.shift", mmu_psize_def.shift); - WRITE_MEMBER_OFFSET("cpu_spec.mmu_features", cpu_spec.mmu_features); -+ WRITE_MEMBER_OFFSET("uts_namespace.name", uts_namespace.name); - - if (SYMBOL(node_data) != NOT_FOUND_SYMBOL) - WRITE_ARRAY_LENGTH("node_data", node_data); -@@ -2743,6 +2755,7 @@ read_vmcoreinfo(void) - READ_MEMBER_OFFSET("vmemmap_backing.list", vmemmap_backing.list); - READ_MEMBER_OFFSET("mmu_psize_def.shift", mmu_psize_def.shift); - READ_MEMBER_OFFSET("cpu_spec.mmu_features", cpu_spec.mmu_features); -+ READ_MEMBER_OFFSET("uts_namespace.name", uts_namespace.name); - - READ_STRUCTURE_SIZE("printk_log", printk_log); - READ_STRUCTURE_SIZE("printk_ringbuffer", printk_ringbuffer); -diff --git a/makedumpfile.h b/makedumpfile.h -index 47f7e79..5f50080 100644 ---- a/makedumpfile-1.6.8/makedumpfile.h -+++ b/makedumpfile-1.6.8/makedumpfile.h -@@ -1728,6 +1728,8 @@ struct size_table { - long cpu_spec; - - long pageflags; -+ -+ long uts_namespace; - }; - - struct offset_table { -@@ -1935,6 +1937,10 @@ struct offset_table { - struct cpu_spec_s { - long mmu_features; - } cpu_spec; -+ -+ struct uts_namespace_s { -+ long name; -+ } uts_namespace; - }; - - /* --- -2.29.2 - diff --git a/kexec-tools.spec b/kexec-tools.spec index 264dd40..d498e0a 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,6 +1,6 @@ %global eppic_ver e8844d3793471163ae4a56d8f95897be9e5bd554 %global eppic_shortver %(c=%{eppic_ver}; echo ${c:0:7}) -%global mkdf_ver 1.6.8 +%global mkdf_ver 1.6.9 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools @@ -93,6 +93,7 @@ Requires: systemd-udev%{?_isa} # # Patches 401 through 500 are meant for s390 kexec-tools enablement # + # # Patches 501 through 600 are meant for ARM kexec-tools enablement # @@ -100,12 +101,6 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # -Patch603: ./kexec-tools-2.0.20-makedumpfile-printk-add-support-for-lockless-ringbuffer.patch -Patch604: ./kexec-tools-2.0.20-makedumpfile-printk-use-committed-finalized-state-value.patch -Patch605: ./kexec-tools-2.0.21-makedumpfile-make-use-of-uts_namespace.name-offset-in-VMCOR.patch -Patch606: ./kexec-tools-2.0.21-makedumpfile-Add-dry-run-option.patch -Patch607: ./kexec-tools-2.0.21-makedumpfile-Add-shorthand-show-stats-option.patch -Patch608: ./kexec-tools-2.0.21-makedumpfile-Show-write-byte-size-in-report-messages.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -121,13 +116,6 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} -%patch603 -p1 -%patch604 -p1 -%patch605 -p1 -%patch606 -p1 -%patch607 -p1 -%patch608 -p1 - %ifarch ppc %define archdef ARCH=ppc %endif diff --git a/sources b/sources index c3da2cf..80b4d4e 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ -SHA512 (makedumpfile-1.6.8.tar.gz) = 15e60688b06013bf86e339ec855774ea2c904d425371ea867101704ba0611c69da891eb3cc96f67eb10197d8c42d217ea28bf11bcaa93ddc2495cbf984c0b7ec SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 SHA512 (kexec-tools-2.0.22.tar.xz) = 7580860f272eee5af52139809f12961e5a5d3a65f4e191183ca9c845410425d25818945ac14ed04a60e6ce474dc2656fc6a14041177b0bf703f450820c7d6aba +SHA512 (makedumpfile-1.6.9.tar.gz) = 9982985498ae641d390c3b87d92aecd263a502f1a4a9e96e145d86d8778b9e778e4ee98034ef4dbe12ed5586c57278917ea5f3c9ae2989ad1ac051215e03b3d9 From 10c309b5f715496d70959a06f7c236cab31fb5a9 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Apr 2021 15:32:08 +0800 Subject: [PATCH 042/454] Add helper to get value by field using "nmcli --get-values" nmcli --get-values connection show /org/freedesktop/NetworkManager/ActiveConnection/1 returns the following value for the corresponding field respectively, Field Value IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160" 802-3-ethernet.s390-subchannels "" bond.options "mode=balance-rr" Signed-off-by: Coiby Xu Acked-by: Kairui Song --- kdump-lib.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 5f53a8a..17414a9 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -372,6 +372,26 @@ get_hwaddr() fi } + +# Get value by a field using "nmcli -g" +# +# "nmcli --get-values" allows us to retrive value(s) by field, for example, +# nmcli --get-values connection show /org/freedesktop/NetworkManager/ActiveConnection/1 +# returns the following value for the corresponding field respectively, +# Field Value +# IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160" +# 802-3-ethernet.s390-subchannels "" +# bond.options "mode=balance-rr" +get_nmcli_value_by_field() +{ + local _nm_show_cmd=$1 + local _field=$2 + + local val=$(LANG=C nmcli --get-values $_field $_nm_show_cmd) + + echo -n "$val" +} + get_ifcfg_by_device() { grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \ From c69578ca431998d7460d40e58769a05b58bab0e8 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Apr 2021 15:32:09 +0800 Subject: [PATCH 043/454] Add helper to get nmcli connection apath by ifname apath (a D-Bus active connection path) is used for nmcli connection operations, e.g. $ nmcli connection show $apath Signed-off-by: Coiby Xu Acked-by: Kairui Song --- kdump-lib.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 17414a9..d74ca7d 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -392,6 +392,20 @@ get_nmcli_value_by_field() echo -n "$val" } +# Get nmcli connection apath (a D-Bus active connection path ) by ifname +# +# apath is used for nmcli connection operations, e.g. +# $ nmcli connection show $apath +get_nmcli_connection_apath_by_ifname() +{ + local _ifname=$1 + local _nm_show_cmd="device show $_ifname" + + local _apath=$(get_nmcli_value_by_field "$_nm_show_cmd" "GENERAL.CON-PATH") + + echo -n "$_apath" +} + get_ifcfg_by_device() { grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \ From 0c292f49c7a148c2ba21c9992371456b1030b54c Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Apr 2021 15:32:10 +0800 Subject: [PATCH 044/454] Add helper to get nmcli connection show cmd by ifname Signed-off-by: Coiby Xu Acked-by: Kairui Song --- kdump-lib.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index d74ca7d..4dcd134 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -406,6 +406,20 @@ get_nmcli_connection_apath_by_ifname() echo -n "$_apath" } +# Get nmcli connection show cmd by ifname +# +# "$_apath" is supposed to not contain any chracter that +# need to be escapded, e.g. space. Otherwise get_nmcli_value_by_field +# would fail. +get_nmcli_connection_show_cmd_by_ifname() +{ + local _ifname="$1" + local _apath=$(get_nmcli_connection_apath_by_ifname "$_ifname") + local _nm_show_cmd="connection show $_apath" + + echo -n "$_nm_show_cmd" +} + get_ifcfg_by_device() { grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \ From 8b08b4f17ba0141eb9c78cb4d626adbdaee433f5 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Apr 2021 15:32:11 +0800 Subject: [PATCH 045/454] Set up s390 znet cmdline by "nmcli --get-values" Now kdumpctl will abort when failing to set up znet. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index a8bfe53..8a53ac6 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -430,17 +430,33 @@ kdump_setup_vlan() { } # setup s390 znet cmdline -# $1: netdev name +# $1: netdev (ifname) +# $2: nmcli connection show output kdump_setup_znet() { + local _netdev="$1" + local _nmcli_cmd="$2" + local s390_prefix="802-3-ethernet.s390-" local _options="" - local _netdev=$1 + local NETTYPE + local SUBCHANNELS - source_ifcfg_file $_netdev + NETTYPE=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}nettype") + SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels") + _options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options") - for i in $OPTIONS; do - _options=${_options},$i - done - echo rd.znet=${NETTYPE},${SUBCHANNELS}${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf + if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then + dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script." + source_ifcfg_file $_netdev + for i in $OPTIONS; do + _options=${_options},$i + done + fi + + if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then + exit 1 + fi + + echo rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf } kdump_get_ip_route() @@ -477,18 +493,23 @@ kdump_get_remote_ip() # initramfs accessing giving destination # $1: destination host kdump_install_net() { - local _destaddr _srcaddr _route _netdev kdumpnic + local _destaddr _srcaddr _route _netdev _nm_show_cmd kdumpnic local _static _proto _ip_conf _ip_opts _ifname_opts _destaddr=$(kdump_get_remote_ip $1) _route=$(kdump_get_ip_route $_destaddr) _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") + _nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev") _netmac=$(kdump_get_mac_addr $_netdev) kdumpnic=$(kdump_setup_ifname $_netdev) if [ "$(uname -m)" = "s390x" ]; then - kdump_setup_znet $_netdev + $(kdump_setup_znet "$_netdev" "$_nm_show_cmd") + if [[ $? != 0 ]]; then + derror "Failed to set up znet" + exit 1 + fi fi _static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) From 6f1badec789c86761f5777af80ba229ec13fc793 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Apr 2021 15:32:12 +0800 Subject: [PATCH 046/454] Set up dns cmdline by parsing "nmcli --get-values" Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 8a53ac6..b186d71 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -94,15 +94,26 @@ source_ifcfg_file() { fi } -# $1: netdev name +# $1: nmcli connection show output kdump_setup_dns() { - local _nameserver _dns + local _netdev="$1" + local _nm_show_cmd="$2" + local _nameserver _dns _tmp array local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf - source_ifcfg_file $1 - - [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile" - [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" + _tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS") + array=(${_tmp//|/ }) + if [[ ${array[@]} ]]; then + for _dns in "${array[@]}" + do + echo "nameserver=$_dns" >> "$_dnsfile" + done + else + dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script" + source_ifcfg_file "$_netdev" + [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile" + [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" + fi while read content; do @@ -546,7 +557,7 @@ kdump_install_net() { echo "$_ifname_opts" >> $_ip_conf fi - kdump_setup_dns "$_netdev" + kdump_setup_dns "$_netdev" "$_nm_show_cmd" if [ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]; then # network-manager module needs this parameter From d5f6d38173f66c0b45e82cb52a66ba0140b7dd22 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Apr 2021 15:32:13 +0800 Subject: [PATCH 047/454] Set up bond cmdline by "nmcli --get-values" Now kdumpctl will exit if failing to set up bond cmdline. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index b186d71..67bcaf0 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -365,7 +365,10 @@ kdump_setup_bridge() { for _dev in `ls /sys/class/net/$_netdev/brif/`; do _kdumpdev=$_dev if kdump_is_bond "$_dev"; then - kdump_setup_bond "$_dev" + $(kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") + if [[ $? != 0 ]]; then + exit 1 + fi elif kdump_is_team "$_dev"; then kdump_setup_team "$_dev" elif kdump_is_vlan "$_dev"; then @@ -380,9 +383,13 @@ kdump_setup_bridge() { echo " bridge=$_netdev:$(echo $_brif | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/41bridge.conf } +# drauct takes bond=[::[:]] syntax to parse +# bond. For example: +# bond=bond0:eth0,eth1:mode=balance-rr kdump_setup_bond() { - local _netdev=$1 - local _dev _mac _slaves _kdumpdev + local _netdev="$1" + local _nm_show_cmd="$2" + local _dev _mac _slaves _kdumpdev _bondoptions for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do _mac=$(kdump_get_perm_addr $_dev) _kdumpdev=$(kdump_setup_ifname $_dev) @@ -390,12 +397,21 @@ kdump_setup_bond() { _slaves+="$_kdumpdev," done echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf - # Get bond options specified in ifcfg - source_ifcfg_file $_netdev + _bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options") - bondoptions=":$(echo $BONDING_OPTS | xargs echo | tr " " ",")" - echo "$bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf + if [[ -z "_bondoptions" ]]; then + dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." + source_ifcfg_file $_netdev + _bondoptions="$(echo $BONDING_OPTS | xargs echo | tr " " ",")" + fi + + if [[ -z "_bondoptions" ]]; then + derror "Get empty bond options" + exit 1 + fi + + echo ":$_bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf } kdump_setup_team() { @@ -432,7 +448,10 @@ kdump_setup_vlan() { derror "Vlan over bridge is not supported!" exit 1 elif kdump_is_bond "$_phydev"; then - kdump_setup_bond "$_phydev" + $(kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") + if [[ $? != 0 ]]; then + exit 1 + fi echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf else _kdumpdev="$(kdump_setup_ifname $_phydev)" @@ -547,7 +566,10 @@ kdump_install_net() { if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then - kdump_setup_bond "$_netdev" + $(kdump_setup_bond "$_netdev" "$_nm_show_cmd") + if [[ $? != 0 ]]; then + exit 1 + fi elif kdump_is_team "$_netdev"; then kdump_setup_team "$_netdev" elif kdump_is_vlan "$_netdev"; then From 8178d7a5a1b164aecea73d9cf3e32ac57a9f33e8 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Apr 2021 15:32:14 +0800 Subject: [PATCH 048/454] Warn the user if network scripts are used Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 67bcaf0..a99a0ea 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -86,6 +86,7 @@ kdump_is_vlan() { source_ifcfg_file() { local ifcfg_file + dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." ifcfg_file=$(get_ifcfg_filename $1) if [ -f "${ifcfg_file}" ]; then . ${ifcfg_file} From d5fe96cd7a779984bf2ba4c8dc51cd10c7e37efd Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Tue, 27 Apr 2021 17:58:40 +0800 Subject: [PATCH 049/454] Disable CMA in kdump 2nd kernel kexec-tools needs to disable CMA for kdump kernel cmdline, otherwise kdump kernel may run out of memory. This patch strips the inherited cma=, hugetlb_cma= cmd line from 1st kernel, and sets to be 0 for 2nd kernel. Signed-off-by: Tao Liu Acked-by: Kairui Song --- kdump.sysconfig | 4 ++-- kdump.sysconfig.aarch64 | 4 ++-- kdump.sysconfig.i386 | 4 ++-- kdump.sysconfig.ppc64 | 4 ++-- kdump.sysconfig.ppc64le | 4 ++-- kdump.sysconfig.s390x | 4 ++-- kdump.sysconfig.x86_64 | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/kdump.sysconfig b/kdump.sysconfig index 30f0c63..70ebf04 100644 --- a/kdump.sysconfig +++ b/kdump.sysconfig @@ -17,11 +17,11 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 reset_devices novmcoredd" +KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 reset_devices novmcoredd cma=0 hugetlb_cma=0" # Any additional kexec arguments required. In most situations, this should # be left empty diff --git a/kdump.sysconfig.aarch64 b/kdump.sysconfig.aarch64 index 6f7830a..fedd3bc 100644 --- a/kdump.sysconfig.aarch64 +++ b/kdump.sysconfig.aarch64 @@ -17,11 +17,11 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory udev.children-max=2 panic=10 swiotlb=noforce novmcoredd" +KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory udev.children-max=2 panic=10 swiotlb=noforce novmcoredd cma=0 hugetlb_cma=0" # Any additional kexec arguments required. In most situations, this should # be left empty diff --git a/kdump.sysconfig.i386 b/kdump.sysconfig.i386 index d2de7d6..7e18c1c 100644 --- a/kdump.sysconfig.i386 +++ b/kdump.sysconfig.i386 @@ -17,11 +17,11 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd" +KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd cma=0 hugetlb_cma=0" # Any additional kexec arguments required. In most situations, this should # be left empty diff --git a/kdump.sysconfig.ppc64 b/kdump.sysconfig.ppc64 index 39b69bb..ebb22f6 100644 --- a/kdump.sysconfig.ppc64 +++ b/kdump.sysconfig.ppc64 @@ -17,11 +17,11 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd" +KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" # Any additional kexec arguments required. In most situations, this should # be left empty diff --git a/kdump.sysconfig.ppc64le b/kdump.sysconfig.ppc64le index 39b69bb..ebb22f6 100644 --- a/kdump.sysconfig.ppc64le +++ b/kdump.sysconfig.ppc64le @@ -17,11 +17,11 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd" +KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" # Any additional kexec arguments required. In most situations, this should # be left empty diff --git a/kdump.sysconfig.s390x b/kdump.sysconfig.s390x index f9218e5..439e462 100644 --- a/kdump.sysconfig.s390x +++ b/kdump.sysconfig.s390x @@ -17,11 +17,11 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="nr_cpus=1 cgroup_disable=memory numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd" +KDUMP_COMMANDLINE_APPEND="nr_cpus=1 cgroup_disable=memory numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd vmcp_cma=0 cma=0 hugetlb_cma=0" # Any additional /sbin/mkdumprd arguments required. MKDUMPRD_ARGS="" diff --git a/kdump.sysconfig.x86_64 b/kdump.sysconfig.x86_64 index 0521893..1285506 100644 --- a/kdump.sysconfig.x86_64 +++ b/kdump.sysconfig.x86_64 @@ -17,11 +17,11 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -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" +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 cma=0 hugetlb_cma=0" # Any additional kexec arguments required. In most situations, this should # be left empty From 13796ca93a80e95dd53419e40c8ace2bf4dde386 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 13 May 2021 16:46:28 +0800 Subject: [PATCH 050/454] Release 2.0.22-2 Signed-off-by: Kairui Song --- kexec-tools.spec | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index d498e0a..11c64cb 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.22 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -355,6 +355,17 @@ done %endif %changelog +* Thu May 13 2021 Kairui Song - 2.0.22-2 +- Disable CMA in kdump 2nd kernel +- Warn the user if network scripts are used +- Set up bond cmdline by "nmcli --get-values" +- Set up dns cmdline by parsing "nmcli --get-values" +- Set up s390 znet cmdline by "nmcli --get-values" +- Add helper to get nmcli connection show cmd by ifname +- Add helper to get nmcli connection apath by ifname +- Add helper to get value by field using "nmcli --get-values" +- Update makedumpfile to 1.6.9 + * Tue May 11 2021 Kairui Song - 2.0.22-1 - Update kexec-tools to 2.0.22 - rd.route should use the name from kdump_setup_ifname From 3423bbc17f5521de8ff80e76d91ce13657b1cea2 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 8 Apr 2021 01:36:49 +0800 Subject: [PATCH 051/454] kdump-lib.sh: introduce a helper to get underlying crypt device Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- kdump-lib.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 4dcd134..ecb2721 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -958,3 +958,20 @@ kdump_get_arch_recommend_size() echo $result return 0 } + +# Print all underlying crypt devices of a block device +# print nothing if device is not on top of a crypt device +# $1: the block device to be checked in maj:min format +get_luks_crypt_dev() +{ + [[ -b /dev/block/$1 ]] || return 1 + + local _type=$(eval "$(blkid -u filesystem,crypto -o export -- /dev/block/$1); echo \$TYPE") + [[ $_type == "crypto_LUKS" ]] && echo $1 + + for _x in /sys/dev/block/$1/slaves/*; do + [[ -f $_x/dev ]] || continue + [[ $_x/subsystem -ef /sys/class/block ]] || continue + get_luks_crypt_dev "$(< "$_x/dev")" + done +} From 1c70cf51c7678499e2d48eec10ad24b839fe9f64 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 18 May 2021 16:13:16 +0800 Subject: [PATCH 052/454] kdump-lib.sh: introduce a helper to get all crypt dev used by kdump Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- kdump-lib.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index ecb2721..e00ea43 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -975,3 +975,24 @@ get_luks_crypt_dev() get_luks_crypt_dev "$(< "$_x/dev")" done } + +# kdump_get_maj_min +# Prints the major and minor of a device node. +# Example: +# $ get_maj_min /dev/sda2 +# 8:2 +kdump_get_maj_min() { + local _majmin + _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)" + printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" +} + +get_all_kdump_crypt_dev() +{ + local _dev _crypt + + for _dev in $(get_block_dump_target); do + _crypt=$(get_luks_crypt_dev $(kdump_get_maj_min "$_dev")) + [[ -n "$_crypt" ]] && echo $_crypt + done +} From 85c725813b49ae9495841b4b55736a26079dc75d Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 8 Apr 2021 01:41:21 +0800 Subject: [PATCH 053/454] mkdumprd: make use of the new get_luks_crypt_dev helper Simplfy the code and also improve the performance. udevadm call is heavy. Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- mkdumprd | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/mkdumprd b/mkdumprd index 50ebdc8..b518078 100644 --- a/mkdumprd +++ b/mkdumprd @@ -325,7 +325,6 @@ get_override_resettable() fi } - # $1: function name for_each_block_target() { @@ -340,8 +339,6 @@ for_each_block_target() return 0 } - - #judge if a specific device with $1 is unresettable #return false if unresettable. is_unresettable() @@ -378,32 +375,15 @@ check_resettable() return 1 } -# $1: maj:min -is_crypt() -{ - local majmin=$1 dev line ID_FS_TYPE="" - - line=$(udevadm info --query=property --path=/sys/dev/block/$majmin \ - | grep "^ID_FS_TYPE") - eval "$line" - [[ "$ID_FS_TYPE" = "crypto_LUKS" ]] && { - dev=$(udevadm info --query=all --path=/sys/dev/block/$majmin | awk -F= '/DEVNAME/{print $2}') - derror "Device $dev is encrypted." - return 0 - } - return 1 -} - check_crypt() { - local _ret _target + local _dev - for_each_block_target is_crypt - _ret=$? - - [ $_ret -eq 0 ] && return - - return 1 + for _dev in $(get_kdump_targets); do + if [[ -n $(get_luks_crypt_dev "$(get_maj_min "$_dev")") ]]; then + derror "Device $_dev is encrypted." && return 1 + fi + done } if ! check_resettable; then From e9e6a2c745d41f5447c0062525c0e4f3f489b903 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 22 Apr 2021 03:27:10 +0800 Subject: [PATCH 054/454] kdumpctl: Add kdumpctl estimate Add a rough esitimation support, currently, following memory usage are checked by this sub command: - System RAM - Kdump Initramfs size - Kdump Kernel image size - Kdump Kernel module size - Kdump userspace user and other runtime allocated memory (currently simply using a fixed value: 64M) - LUKS encryption memory usage The output of kdumpctl estimate looks like this: # kdumpctl estimate Reserved crashkernel: 256M Recommanded crashkernel: 160M Kernel image size: 47M Kernel modules size: 12M Initramfs size: 19M Runtime reservation: 64M Large modules: xfs: 1892352 nouveau: 2318336 And if the kdump target is encrypted: # kdumpctl estimate Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement Reserved crashkernel: 256M Recommanded crashkernel: 655M Kernel image size: 47M Kernel modules size: 12M Initramfs size: 19M Runtime reservation: 64M LUKS required size: 512M Large modules: xfs: 1892352 nouveau: 2318336 WARNING: Current crashkernel size is lower than recommanded size 655M. The "Recommanded" value is calculated based on memory usages mentioned above, and will be adjusted accodingly to be no less than the value provided by kdump_get_arch_recommend_size. Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- kdump-lib.sh | 71 ++++++++++++++++++++++++++++++++++++++ kdumpctl | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++- kdumpctl.8 | 5 +++ 3 files changed, 171 insertions(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index e00ea43..74072c5 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -996,3 +996,74 @@ get_all_kdump_crypt_dev() [[ -n "$_crypt" ]] && echo $_crypt done } + +check_vmlinux() +{ + # Use readelf to check if it's a valid ELF + readelf -h $1 &>/dev/null || return 1 +} + +get_vmlinux_size() +{ + local size=0 + + while read _type _offset _virtaddr _physaddr _fsize _msize _flg _aln; do + size=$(( $size + $_msize )) + done <<< $(readelf -l -W $1 | grep "^ LOAD" 2>/dev/stderr) + + echo $size +} + +try_decompress() +{ + # The obscure use of the "tr" filter is to work around older versions of + # "grep" that report the byte offset of the line instead of the pattern. + + # Try to find the header ($1) and decompress from here + for pos in `tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"` + do + if ! type -P $3 > /dev/null; then + ddebug "Signiature detected but '$3' is missing, skip this decompressor" + break + fi + + pos=${pos%%:*} + tail -c+$pos "$img" | $3 > $5 2> /dev/null + if check_vmlinux $5; then + ddebug "Kernel is extracted with '$3'" + return 0 + fi + done + + return 1 +} + +# Borrowed from linux/scripts/extract-vmlinux +get_kernel_size() +{ + # Prepare temp files: + local img=$1 tmp=$(mktemp /tmp/vmlinux-XXX) + trap "rm -f $tmp" 0 + + # Try to check if it's a vmlinux already + check_vmlinux $img && get_vmlinux_size $img && return 0 + + # That didn't work, so retry after decompression. + try_decompress '\037\213\010' xy gunzip $img $tmp || \ + try_decompress '\3757zXZ\000' abcde unxz $img $tmp || \ + try_decompress 'BZh' xy bunzip2 $img $tmp || \ + try_decompress '\135\0\0\0' xxx unlzma $img $tmp || \ + try_decompress '\211\114\132' xy 'lzop -d' $img $tmp || \ + try_decompress '\002!L\030' xxx 'lz4 -d' $img $tmp || \ + try_decompress '(\265/\375' xxx unzstd $img $tmp + + # Finally check for uncompressed images or objects: + [[ $? -eq 0 ]] && get_vmlinux_size $tmp && return 0 + + # Fallback to use iomem + local _size=0 + for _seg in $(cat /proc/iomem | grep -E "Kernel (code|rodata|data|bss)" | cut -d ":" -f 1); do + _size=$(( $_size + 0x${_seg#*-} - 0x${_seg%-*} )) + done + echo $_size +} diff --git a/kdumpctl b/kdumpctl index 009d259..978dae5 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1249,6 +1249,97 @@ rebuild() { return $? } +do_estimate() { + local kdump_mods + local -A large_mods + local baseline + local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommanded_size + local size_mb=$(( 1024 * 1024 )) + + setup_initrd + if [ ! -f "$TARGET_INITRD" ]; then + derror "kdumpctl estimate: kdump initramfs is not built yet." + exit 1 + fi + + kdump_mods="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')" + baseline=$(kdump_get_arch_recommend_size) + if [[ "${baseline: -1}" == "M" ]]; then + baseline=${baseline%M} + elif [[ "${baseline: -1}" == "G" ]]; then + baseline=$(( ${baseline%G} * 1024 )) + elif [[ "${baseline: -1}" == "T" ]]; then + baseline=$(( ${baseline%Y} * 1048576 )) + fi + + # The default value when using crashkernel=auto + baseline_size=$((baseline * size_mb)) + # Current reserved crashkernel size + reserved_size=$(cat /sys/kernel/kexec_crash_size) + # A pre-estimated value for userspace usage and kernel + # runtime allocation, 64M should good for most cases + runtime_size=$((64 * size_mb)) + # Kernel image size + kernel_size=$(get_kernel_size "$KDUMP_KERNEL") + # Kdump initramfs size + initrd_size=$(du -b "$TARGET_INITRD" | awk '{print $1}') + # Kernel modules static size after loaded + mod_size=0 + while read -r _name _size _; do + if [[ ! " $kdump_mods " == *" $_name "* ]]; then + continue + fi + mod_size=$((mod_size + _size)) + + # Mark module with static size larger than 2M as large module + if [[ $((_size / size_mb)) -ge 1 ]]; then + large_mods[$_name]=$_size + fi + done <<< "$(< /proc/modules)" + + # Extra memory usage required for LUKS2 decryption + crypt_size=0 + for _dev in $(get_all_kdump_crypt_dev); do + _crypt_info=$(cryptsetup luksDump "/dev/block/$_dev") + [[ $(echo "$_crypt_info" | sed -n "s/^Version:\s*\(.*\)/\1/p" ) == "2" ]] || continue + for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n ); do + crypt_size=$((crypt_size + _mem * 1024)) + break + done + done + [[ $crypt_size -ne 0 ]] && echo -e "Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement\n" + + estimated_size=$((kernel_size + mod_size + initrd_size + runtime_size + crypt_size)) + if [[ $baseline_size -gt $estimated_size ]]; then + recommanded_size=$baseline_size + else + recommanded_size=$estimated_size + fi + + echo "Reserved crashkernel: $((reserved_size / size_mb))M" + echo "Recommanded crashkernel: $((recommanded_size / size_mb))M" + echo + echo "Kernel image size: $((kernel_size / size_mb))M" + echo "Kernel modules size: $((mod_size / size_mb))M" + echo "Initramfs size: $((initrd_size / size_mb))M" + echo "Runtime reservation: $((runtime_size / size_mb))M" + [[ $crypt_size -ne 0 ]] && \ + echo "LUKS required size: $((crypt_size / size_mb))M" + echo -n "Large modules:" + if [[ "${#large_mods[@]}" -eq 0 ]]; then + echo " " + else + echo "" + for _mod in "${!large_mods[@]}"; do + echo " $_mod: ${large_mods[$_mod]}" + done + fi + + if [[ $reserved_size -le $recommanded_size ]]; then + echo "WARNING: Current crashkernel size is lower than recommanded size $((recommanded_size / size_mb))M." + fi +} + if [ ! -f "$KDUMP_CONFIG_FILE" ]; then derror "Error: No kdump config file found!" exit 1 @@ -1304,8 +1395,11 @@ main () showmem) show_reserved_mem ;; + estimate) + do_estimate + ;; *) - dinfo $"Usage: $0 {start|stop|status|restart|reload|rebuild|propagate|showmem}" + dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|propagate|showmem}" exit 1 esac } diff --git a/kdumpctl.8 b/kdumpctl.8 index ae97af7..a32a972 100644 --- a/kdumpctl.8 +++ b/kdumpctl.8 @@ -44,6 +44,11 @@ impossible to use password authentication during kdump. .TP .I showmem Prints the size of reserved memory for crash kernel in megabytes. +.TP +.I estimate +Estimate a suitable crashkernel value for current machine. This is a +best-effort estimate. It will print a recommanded crashkernel value +based on current kdump setup, and list some details of memory usage. .SH "SEE ALSO" .BR kdump.conf (5), From 45377836b014e22c27e5a210e679501f97ba4525 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 25 May 2021 09:26:09 +0800 Subject: [PATCH 055/454] kdump-lib.sh: fix the case if no enough total RAM for kdump in get_recommend_size() For crashkernel=auto policy, if total RAM size is under a throttle, there is no memory reserved for kdump. Also correct a trivial bug by correcting the arch name. Signed-off-by: Pingfan Liu Acked-by: Kairui Song --- kdump-lib.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 74072c5..ecf909e 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -913,6 +913,11 @@ get_recommend_size() last_sz="" last_unit="" + start=${_ck_cmdline: :1} + if [ $mem_size -lt $start ]; then + echo "0M" + return + fi IFS=',' for i in $_ck_cmdline; do end=$(echo $i | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $1 }') @@ -940,9 +945,9 @@ kdump_get_arch_recommend_size() fi arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr [:lower:] [:upper:]) - if [ $arch == "X86_64" ] || [ $arch == "S390" ]; then + if [ $arch == "X86_64" ] || [ $arch == "S390X" ]; then ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" - elif [ $arch == "ARM64" ]; then + elif [ $arch == "AARCH64" ]; then ck_cmdline="2G-:448M" elif [ $arch == "PPC64LE" ]; then if is_fadump_capable; then From 39a642b66b2b4341a1345b63c5731e4ab90ad1b5 Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Tue, 1 Jun 2021 16:46:58 +0530 Subject: [PATCH 056/454] kdump-lib.sh: fix a warning in prepare_kdump_bootinfo() Fix the warning observed when KDUMP_KERNELVER is specified: kdumpctl[10926]: /lib/kdump/kdump-lib.sh: line 697: [: missing `]' Signed-off-by: Hari Bathini Acked-by: Kairui Song --- kdump-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index ecf909e..27741fb 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -746,7 +746,7 @@ prepare_kdump_bootinfo() local boot_imglist boot_dirlist boot_initrdlist curr_kver="$(uname -r)" local machine_id - if [ -z "$KDUMP_KERNELVER"]; then + if [ -z "$KDUMP_KERNELVER" ]; then KDUMP_KERNELVER="$(uname -r)" fi From 108258139a24b596be454c9aaa07b6ebf96e49a1 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 26 Apr 2021 17:09:55 +0800 Subject: [PATCH 057/454] Don's try to restart dracut-initqueue if it's already there kdump's dump_to_rootfs will try to start initqueue unconditionally. dump_to_rootfs will run after systemd isolate to emergency target, so this is currently accetable. But there is a problem when initqueue starts the emergency action because of initqueue timeout. dump_to_rootfs will start initqueue and lead to timeout again. So following patch will remove the previous isolation wrapper, and detect the service status here. Previous isolation makes the detection impossible. Now this detection will be valid and helpful to prevent double timeout or hang. Signed-off-by: Kairui Song Acked-by: Coiby Xu --- kdump-lib-initramfs.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index d0d124f..e359a15 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -222,8 +222,11 @@ save_opalcore_fs() { dump_to_rootfs() { - dinfo "Trying to bring up rootfs device" - systemctl start dracut-initqueue + if [[ $(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p") == "inactive" ]]; then + dinfo "Trying to bring up initqueue for rootfs mount" + systemctl start dracut-initqueue + fi + dinfo "Waiting for rootfs mount, will timeout after 90 seconds" systemctl start sysroot.mount From a2306346bc6671e99f8af137785a442ec0020d57 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 26 Apr 2021 17:09:56 +0800 Subject: [PATCH 058/454] Remove the kdump error handler isolation wrapper The wrapper is introduced in commit 002337c, according to the commit message, the only usage of the wrapper is when dracut-initqueue calls "systemctl start emergency" directly. In that case, emergency is started, but not in a isolation mode, which means dracut-initqueue is still running. On the other hand, emergency will call "systemctl start dracut-initqueue" again when default action is dump_to_rootfs. systemd would block on the last dracut-initqueue, waiting for the first instance to exit, which leaves us hang. In previous commit we added initqueue status detect in dump_to_rootfs, so now even without the wrapper, it will not hang. And actually, previously, with the wrapper, emergency might still hang for like 30s. When dracut called emergency service because initqueue timed out, dump_to_rootfs will try start initqueue again and timeout again. Now with the wrapper removed, we can avoid these two kinds of hangs, bacause without the isolation we can detect initqueue service status correctly in such case. Also remove the invalid header comments in service file, the service is not part of systemd code. And sync the service spec with dracut. Signed-off-by: Kairui Song Acked-by: Coiby Xu --- dracut-kdump-emergency.service | 25 +++++++++++----------- dracut-kdump-error-handler.service | 33 ------------------------------ dracut-module-setup.sh | 1 - kexec-tools.spec | 2 -- 4 files changed, 12 insertions(+), 49 deletions(-) delete mode 100644 dracut-kdump-error-handler.service diff --git a/dracut-kdump-emergency.service b/dracut-kdump-emergency.service index e023284..f2f6fad 100644 --- a/dracut-kdump-emergency.service +++ b/dracut-kdump-emergency.service @@ -1,27 +1,26 @@ -# This file is part of systemd. -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. - -# This service will be placed in kdump initramfs and replace both the systemd -# emergency service and dracut emergency shell. IOW, any emergency will be -# kick this service and in turn isolating to kdump error handler. +# This service will run the real kdump error handler code. Executing the +# failure action configured in kdump.conf [Unit] -Description=Kdump Emergency +Description=Kdump Error Handler DefaultDependencies=no -IgnoreOnIsolate=yes +After=systemd-vconsole-setup.service +Wants=systemd-vconsole-setup.service [Service] -ExecStart=/usr/bin/systemctl --no-block isolate kdump-error-handler.service +Environment=HOME=/ +Environment=DRACUT_SYSTEMD=1 +Environment=NEWROOT=/sysroot +WorkingDirectory=/ +ExecStart=/bin/kdump-error-handler.sh +ExecStopPost=-/bin/rm -f -- /.console_lock Type=oneshot StandardInput=tty-force StandardOutput=inherit StandardError=inherit KillMode=process IgnoreSIGPIPE=no +TasksMax=infinity # Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash # terminates cleanly. diff --git a/dracut-kdump-error-handler.service b/dracut-kdump-error-handler.service deleted file mode 100644 index a23b75e..0000000 --- a/dracut-kdump-error-handler.service +++ /dev/null @@ -1,33 +0,0 @@ -# This file is part of systemd. -# -# systemd is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation; either version 2.1 of the License, or -# (at your option) any later version. - -# This service will run the real kdump error handler code. Executing the -# failure action configured in kdump.conf - -[Unit] -Description=Kdump Error Handler -DefaultDependencies=no -After=systemd-vconsole-setup.service -Wants=systemd-vconsole-setup.service -AllowIsolate=yes - -[Service] -Environment=HOME=/ -Environment=DRACUT_SYSTEMD=1 -Environment=NEWROOT=/sysroot -WorkingDirectory=/ -ExecStart=/bin/kdump-error-handler.sh -Type=oneshot -StandardInput=tty-force -StandardOutput=inherit -StandardError=inherit -KillMode=process -IgnoreSIGPIPE=no - -# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash -# terminates cleanly. -KillSignal=SIGHUP diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index a99a0ea..68ee28e 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1026,7 +1026,6 @@ install() { inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service" systemctl -q --root "$initdir" add-wants initrd.target kdump-capture.service inst "$moddir/kdump-error-handler.sh" "/usr/bin/kdump-error-handler.sh" - inst "$moddir/kdump-error-handler.service" "$systemdsystemunitdir/kdump-error-handler.service" # Replace existing emergency service and emergency target cp "$moddir/kdump-emergency.service" "$initdir/$systemdsystemunitdir/emergency.service" cp "$moddir/kdump-emergency.target" "$initdir/$systemdsystemunitdir/emergency.target" diff --git a/kexec-tools.spec b/kexec-tools.spec index 11c64cb..e94ed02 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -49,7 +49,6 @@ Source101: dracut-module-setup.sh Source102: dracut-monitor_dd_progress Source103: dracut-kdump-error-handler.sh Source104: dracut-kdump-emergency.service -Source105: dracut-kdump-error-handler.service Source106: dracut-kdump-capture.service Source107: dracut-kdump-emergency.target Source108: dracut-early-kdump.sh @@ -220,7 +219,6 @@ cp %{SOURCE101} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpb cp %{SOURCE102} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE102}} cp %{SOURCE103} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE103}} cp %{SOURCE104} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE104}} -cp %{SOURCE105} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE105}} cp %{SOURCE106} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE106}} cp %{SOURCE107} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE107}} chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE100}} From 41980f30d9f5806a2e34e30fe279167c12d0ae75 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 26 Apr 2021 17:09:57 +0800 Subject: [PATCH 059/454] Use a customized emergency shell Use a modified and minimized version of emergency shell. The differences of this kdump shell and dracut emergency shell are: - Kdump shell won't generate a rdsosreport automatically - Customized prompts - Never ask root password - Won't tangle with dracut's emergency_action. If emergency_action is set, dracut emergency shell will perform dracut's emergency_action instead of kdump final_action on exit. - If rd.shell=no is set, kdump shell will still work, dracut emergency shell won't, even if kdump failure_action is set to shell. Signed-off-by: Kairui Song Acked-by: Coiby Xu --- kdump-lib-initramfs.sh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index e359a15..ca6a825 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -237,10 +237,35 @@ dump_to_rootfs() kdump_emergency_shell() { - echo "PS1=\"kdump:\\\${PWD}# \"" >/etc/profile - ddebug "Switching to dracut emergency..." - /bin/dracut-emergency - rm -f /etc/profile + ddebug "Switching to kdump emergency shell..." + + [ -f /etc/profile ] && . /etc/profile + export PS1='kdump:${PWD}# ' + + . /lib/dracut-lib.sh + if [ -f /dracut-state.sh ]; then + . /dracut-state.sh 2>/dev/null + fi + + source_conf /etc/conf.d + + type plymouth >/dev/null 2>&1 && plymouth quit + + source_hook "emergency" + while read _tty rest; do + ( + echo + echo + echo 'Entering kdump emergency mode.' + echo 'Type "journalctl" to view system logs.' + echo 'Type "rdsosreport" to generate a sosreport, you can then' + echo 'save it elsewhere and attach it to a bug report.' + echo + echo + ) > /dev/$_tty + done < /proc/consoles + sh -i -l + /bin/rm -f -- /.console_lock } do_failure_action() From 7d472515688fb330eee76dac1c39ae628398f757 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 7 Jun 2021 07:26:03 +0800 Subject: [PATCH 060/454] Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet This patch fixes bz1941106 and bz1941905 which passed empty rd.znet to the kernel command line in the following cases, - The IBM (Z15) KVM guest uses virtio for all devices including network device, so there is no znet device for IBM KVM guest. So we can't assume a s390x machine always has a znet device. - When a bridged network is used, kexec-tools tries to obtain the znet configuration from the ifcfg script of the bridged network rather than from the ifcfg script of znet device. We can iterate /sys/bus/ccwgroup/devices to tell if there if there is a znet network device. By getting an ifname from znet, we can also avoid mistaking the slave netdev as a znet network device in a bridged network or bonded network. Note: This patch also assumes there is only one znet device as commit 7148c0a30dfc48221eadf255e8a89619f98a8752 ("add s390x netdev setup") which greatly simplifies the code. According to IBM [1], there could be more than znet devices for a z/VM system and a z/VM system may have a non-znet network device like ConnectX. Since kdump_setup_znet was introduced in 2012 and so far there is no known customer complaint that invalidates this assumption I think it's safe to assume an IBM z/VM system only has one znet device. Besides, there is no z/VM system found on beaker to test the alternative scenarios. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1941905#c13 Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 68ee28e..35a961a 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -460,6 +460,34 @@ kdump_setup_vlan() { fi } +# find online znet device +# return ifname (_netdev) +# code reaped from the list_configured function of +# https://github.com/hreinecke/s390-tools/blob/master/zconf/znetconf +find_online_znet_device() { + local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" + local NETWORK_DEVICES d ifname ONLINE + NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR -type l) + for d in $NETWORK_DEVICES + do + read ONLINE < $d/online + if [ $ONLINE -ne 1 ]; then + continue + fi + # determine interface name, if there (only for qeth and if + # device is online) + if [ -f $d/if_name ] + then + read ifname < $d/if_name + elif [ -d $d/net ] + then + ifname=$(ls $d/net/) + fi + [ -n "$ifname" ] && break + done + echo -n "$ifname" +} + # setup s390 znet cmdline # $1: netdev (ifname) # $2: nmcli connection show output @@ -526,6 +554,7 @@ kdump_get_remote_ip() kdump_install_net() { local _destaddr _srcaddr _route _netdev _nm_show_cmd kdumpnic local _static _proto _ip_conf _ip_opts _ifname_opts + local _znet_netdev _nm_show_cmd_znet _destaddr=$(kdump_get_remote_ip $1) _route=$(kdump_get_ip_route $_destaddr) @@ -535,8 +564,10 @@ kdump_install_net() { _netmac=$(kdump_get_mac_addr $_netdev) kdumpnic=$(kdump_setup_ifname $_netdev) - if [ "$(uname -m)" = "s390x" ]; then - $(kdump_setup_znet "$_netdev" "$_nm_show_cmd") + _znet_netdev=$(find_online_znet_device) + if [[ -n "$_znet_netdev" ]]; then + _nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev") + $(kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet") if [[ $? != 0 ]]; then derror "Failed to set up znet" exit 1 From 2d9504c4a4dc5e2c659fbd8810b1fed681e5b4ba Mon Sep 17 00:00:00 2001 From: Lianbo Jiang Date: Tue, 1 Jun 2021 18:33:44 +0800 Subject: [PATCH 061/454] mkdumprd: display the absolute path of dump location in the check_user_configured_target() When kdump service fails, the current errors do not display the absolute path of dump location(marked it as "^"), for example: kdump: kexec: unloaded kdump kernel kdump: Stopping kdump: [OK] kdump: Detected change(s) in the following file(s): /etc/kdump.conf kdump: Rebuilding /boot/initramfs-4.18.0-304.el8.x86_64kdump.img kdump: Dump path "/var1/crash" does not exist in dump target "UUID=c202ef45-3ac3-4adb-85e7-307a916757f0" ^^^^^^^^^^^ kdump: mkdumprd: failed to make kdump initrd kdump: Starting kdump: [FAILED] Here, it should output the absolute path of dump location with this format: "/". To fix it, let's extend the relative pathname to the absolute pathname in check_user_configured_target(). Signed-off-by: Lianbo Jiang Acked-by: Kairui Song --- mkdumprd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdumprd b/mkdumprd index b518078..6d699c3 100644 --- a/mkdumprd +++ b/mkdumprd @@ -246,7 +246,7 @@ check_user_configured_target() # For user configured target, use $SAVE_PATH as the dump path within the target if [ ! -d "$_mnt/$SAVE_PATH" ]; then - perror_exit "Dump path \"$SAVE_PATH\" does not exist in dump target \"$_target\"" + perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\"" fi check_size fs "$_target" From 0a15d859bbcec7415f12a1123d00e223b9f864be Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 7 Jun 2021 14:40:50 +0800 Subject: [PATCH 062/454] selftest: fix the error of misplacing double quotes Signed-off-by: Coiby Xu Acked-by: Kairui Song --- tests/scripts/testcases/nfs-kdump/0-server.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/testcases/nfs-kdump/0-server.sh b/tests/scripts/testcases/nfs-kdump/0-server.sh index 41a0212..cf54e70 100755 --- a/tests/scripts/testcases/nfs-kdump/0-server.sh +++ b/tests/scripts/testcases/nfs-kdump/0-server.sh @@ -17,7 +17,7 @@ on_build() { img_run_cmd "systemctl enable dnsmasq" img_run_cmd 'echo DEVICE="eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo BOOTPROTO="none >> /etc/sysconfig/network-scripts/ifcfg-eth0"' + img_run_cmd 'echo BOOTPROTO="none" >> /etc/sysconfig/network-scripts/ifcfg-eth0' img_run_cmd 'echo ONBOOT="yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0' img_run_cmd 'echo PREFIX="24" >> /etc/sysconfig/network-scripts/ifcfg-eth0' img_run_cmd 'echo IPADDR="192.168.77.1" >> /etc/sysconfig/network-scripts/ifcfg-eth0' From 560c0e8a7b1ca03ae881b80419b05d129c8a035d Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 7 Jun 2021 14:40:52 +0800 Subject: [PATCH 063/454] selftest: Make test_base_image depends on EXTRA_RPMS test_base_image should depend on EXTRA_RPMS so it gets rebuild when EXTRA_RPMS changes. Fixes: commit bbc064f9582080124a4acc41f7e33e21c4f18a4f ("selftest: add EXTRA_RPMs so dracut RPMs can be installed onto the image to run the tests") Signed-off-by: Coiby Xu Acked-by: Kairui Song --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 4e9c55f..8fb38c7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -67,7 +67,7 @@ $(BUILD_ROOT)/inst-base-image: $(BUILD_ROOT)/base-image $(BUILD_ROOT)/inst-base-image \ $(TEST_ROOT)/scripts/build-scripts/base-image.sh -$(TEST_ROOT)/output/test-base-image: $(BUILD_ROOT)/inst-base-image $(KEXEC_TOOLS_RPM) $(KEXEC_TOOLS_TEST_SRC) +$(TEST_ROOT)/output/test-base-image: $(BUILD_ROOT)/inst-base-image $(KEXEC_TOOLS_RPM) $(KEXEC_TOOLS_TEST_SRC) $(EXTRA_RPMS) @echo "Building test base image" mkdir -p $(TEST_ROOT)/output $(TEST_ROOT)/scripts/build-image.sh \ From 62578ace21227f1b584cf652b60775ab6035b803 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 7 Jun 2021 14:40:53 +0800 Subject: [PATCH 064/454] selftest: ignore all spaces when compare the dmesg files For the log entry that has multiple lines, "makedumpfile --dump-dmesg" would indent the remaining lines while vmcore-dmesg doesn't. For example, vmcore-dmesg.txt and vmcore-dmesg.txt.2 are the outputs of vmcore-dmesg and "makedumpfile --dump-dmesg" respectively, ``` diff -u vmcore-dmesg.txt vmcore-dmesg.txt.2 --- vmcore-dmesg.txt 2021-03-28 22:13:09.986000000 -0400 +++ vmcore-dmesg.txt.2 2021-03-28 22:13:39.920106131 -0400 @@ -397,9 +397,9 @@ [ 1.710742] vc vcsa: hash matches [ 1.711938] RAS: Correctable Errors collector initialized. [ 1.713736] Unstable clock detected, switching default tracing clock to "global" -If you want to keep using the local clock, then add: - "trace_clock=local" -on the kernel command line + If you want to keep using the local clock, then add: + "trace_clock=local" + on the kernel command line [ 1.750539] ata1.01: NODEV after polling detection [ 1.750973] ata1.00: ATA-7: QEMU HARDDISK, 2.5+, max UDMA/100 [ 1.752885] ata1.00: 8388608 sectors, multi 16: LBA48 ``` Quite often, all three tests could fail because of the above difference. So let's ignore all the spaces. This patch could fix bz1952299 [1]. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1952299 Signed-off-by: Coiby Xu Acked-by: Kairui Song --- tests/scripts/kexec-kdump-test/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/kexec-kdump-test/init.sh b/tests/scripts/kexec-kdump-test/init.sh index f427905..deacb51 100755 --- a/tests/scripts/kexec-kdump-test/init.sh +++ b/tests/scripts/kexec-kdump-test/init.sh @@ -95,7 +95,7 @@ has_valid_vmcore_dir() { return 1 fi - if ! diff $vmcore_dir/vmcore-dmesg.txt.2 $vmcore_dir/vmcore-dmesg.txt; then + if ! diff -w $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 From 302be5c34b400b6dcb948f18fd1ee6d254a3d8bd Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Sun, 20 Jun 2021 02:37:47 +0800 Subject: [PATCH 065/454] Release 2.0.22-3 Signed-off-by: Kairui Song --- kexec-tools.spec | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index e94ed02..7b29b0e 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.22 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -353,6 +353,21 @@ done %endif %changelog +* Sun Jun 20 2021 Kairui Song - 2.0.22-3 +- selftest: Make test_base_image depends on EXTRA_RPMS +- selftest: fix the error of misplacing double quotes +- mkdumprd: display the absolute path of dump location in the check_user_configured_target() +- Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet +- Use a customized emergency shell +- Remove the kdump error handler isolation wrapper +- Don's try to restart dracut-initqueue if it's already there +- kdump-lib.sh: fix a warning in prepare_kdump_bootinfo() +- kdump-lib.sh: fix the case if no enough total RAM for kdump in get_recommend_size() +- kdumpctl: Add kdumpctl estimate +- mkdumprd: make use of the new get_luks_crypt_dev helper +- kdump-lib.sh: introduce a helper to get all crypt dev used by kdump +- kdump-lib.sh: introduce a helper to get underlying crypt device + * Thu May 13 2021 Kairui Song - 2.0.22-2 - Disable CMA in kdump 2nd kernel - Warn the user if network scripts are used From 18b9b763de77e151ea013e9d033a7242b3d86235 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Tue, 22 Jun 2021 21:30:25 +0800 Subject: [PATCH 066/454] Increase SECTION_MAP_LAST_BIT to 5 Backport from upstream. commit 646456862df8926ba10dd7330abf3bf0f887e1b6 Author: Kazuhito Hagio Date: Wed May 26 14:31:26 2021 +0900 [PATCH] Increase SECTION_MAP_LAST_BIT to 5 * Required for kernel 5.12 Kernel commit 1f90a3477df3 ("mm: teach pfn_to_online_page() about ZONE_DEVICE section collisions") added a section flag (SECTION_TAINT_ZONE_DEVICE) and causes makedumpfile an error on some machines like this: __vtop4_x86_64: Can't get a valid pmd_pte. readmem: Can't convert a virtual address(ffffe2bdc2000000) to physical address. readmem: type_addr: 0, addr:ffffe2bdc2000000, size:32768 __exclude_unnecessary_pages: Can't read the buffer of struct page. create_2nd_bitmap: Can't exclude unnecessary pages. Increase SECTION_MAP_LAST_BIT to 5 to fix this. The bit had not been used until the change, so we can just increase the value. Signed-off-by: Kazuhito Hagio Signed-off-by: Tao Liu Acked-by: Kairui Song --- ...e-Increase-SECTION_MAP_LAST_BIT-to-5.patch | 42 +++++++++++++++++++ kexec-tools.spec | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch diff --git a/kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch b/kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch new file mode 100644 index 0000000..a59bef1 --- /dev/null +++ b/kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch @@ -0,0 +1,42 @@ +From 646456862df8926ba10dd7330abf3bf0f887e1b6 Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Wed, 26 May 2021 14:31:26 +0900 +Subject: [PATCH] Increase SECTION_MAP_LAST_BIT to 5 + +* Required for kernel 5.12 + +Kernel commit 1f90a3477df3 ("mm: teach pfn_to_online_page() about +ZONE_DEVICE section collisions") added a section flag +(SECTION_TAINT_ZONE_DEVICE) and causes makedumpfile an error on +some machines like this: + + __vtop4_x86_64: Can't get a valid pmd_pte. + readmem: Can't convert a virtual address(ffffe2bdc2000000) to physical address. + readmem: type_addr: 0, addr:ffffe2bdc2000000, size:32768 + __exclude_unnecessary_pages: Can't read the buffer of struct page. + create_2nd_bitmap: Can't exclude unnecessary pages. + +Increase SECTION_MAP_LAST_BIT to 5 to fix this. The bit had not +been used until the change, so we can just increase the value. + +Signed-off-by: Kazuhito Hagio +--- + makedumpfile.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/makedumpfile-1.6.9/makedumpfile.h b/makedumpfile-1.6.9/makedumpfile.h +index 93aa774..79046f2 100644 +--- a/makedumpfile-1.6.9/makedumpfile.h ++++ b/makedumpfile-1.6.9/makedumpfile.h +@@ -195,7 +195,7 @@ isAnon(unsigned long mapping) + * 2. it has been verified that (1UL<<2) was never set, so it is + * safe to mask that bit off even in old kernels. + */ +-#define SECTION_MAP_LAST_BIT (1UL<<4) ++#define SECTION_MAP_LAST_BIT (1UL<<5) + #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) + #define NR_SECTION_ROOTS() divideup(num_section, SECTIONS_PER_ROOT()) + #define SECTION_NR_TO_PFN(sec) ((sec) << PFN_SECTION_SHIFT()) +-- +2.29.2 + diff --git a/kexec-tools.spec b/kexec-tools.spec index 7b29b0e..ca2e30c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -100,6 +100,7 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # +Patch601: ./kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -115,6 +116,8 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} +%patch601 -p1 + %ifarch ppc %define archdef ARCH=ppc %endif From 0feb109818c53bf1f7e6acd55ca02a119855b77b Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Tue, 22 Jun 2021 21:30:26 +0800 Subject: [PATCH 067/454] check for invalid physical address of /proc/kcore when finding max_paddr Backport from upstream. commit 38d921a2ef50ebd36258097553626443ffe27496 Author: Coiby Xu Date: Tue Jun 15 18:26:31 2021 +0800 [PATCH] check for invalid physical address of /proc/kcore when finding max_paddr Kernel commit 464920104bf7adac12722035bfefb3d772eb04d8 ("/proc/kcore: update physical address for kcore ram and text") sets an invalid paddr (0xffffffffffffffff = -1) for PT_LOAD segments of not direct mapped regions: $ readelf -l /proc/kcore ... Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align NOTE 0x0000000000000120 0x0000000000000000 0x0000000000000000 0x0000000000002320 0x0000000000000000 0x0 LOAD 0x1000000000010000 0xd000000000000000 0xffffffffffffffff ^^^^^^^^^^^^^^^^^^ 0x0001f80000000000 0x0001f80000000000 RWE 0x10000 makedumpfile uses max_paddr to calculate the number of sections for sparse memory model thus wrong number is obtained based on max_paddr (-1). This error could lead to the failure of copying /proc/kcore for RHEL-8.5 on ppc64le machine [1]: $ makedumpfile /proc/kcore vmcore1 get_mem_section: Could not validate mem_section. get_mm_sparsemem: Can't get the address of mem_section. makedumpfile Failed. Let's check if the phys_start of the segment is a valid physical address to fix this problem. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1965267 Reported-by: Xiaoying Yan Signed-off-by: Coiby Xu Signed-off-by: Tao Liu Acked-by: Kairui Song --- ...ss-proc-kcore-when-finding-max_paddr.patch | 60 +++++++++++++++++++ kexec-tools.spec | 2 + 2 files changed, 62 insertions(+) create mode 100644 kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch diff --git a/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch b/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch new file mode 100644 index 0000000..f79ea55 --- /dev/null +++ b/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch @@ -0,0 +1,60 @@ +From 38d921a2ef50ebd36258097553626443ffe27496 Mon Sep 17 00:00:00 2001 +From: Coiby Xu +Date: Tue, 15 Jun 2021 18:26:31 +0800 +Subject: [PATCH] check for invalid physical address of /proc/kcore + when finding max_paddr + +Kernel commit 464920104bf7adac12722035bfefb3d772eb04d8 ("/proc/kcore: +update physical address for kcore ram and text") sets an invalid paddr +(0xffffffffffffffff = -1) for PT_LOAD segments of not direct mapped +regions: + + $ readelf -l /proc/kcore + ... + Program Headers: + Type Offset VirtAddr PhysAddr + FileSiz MemSiz Flags Align + NOTE 0x0000000000000120 0x0000000000000000 0x0000000000000000 + 0x0000000000002320 0x0000000000000000 0x0 + LOAD 0x1000000000010000 0xd000000000000000 0xffffffffffffffff + ^^^^^^^^^^^^^^^^^^ + 0x0001f80000000000 0x0001f80000000000 RWE 0x10000 + +makedumpfile uses max_paddr to calculate the number of sections for +sparse memory model thus wrong number is obtained based on max_paddr +(-1). This error could lead to the failure of copying /proc/kcore +for RHEL-8.5 on ppc64le machine [1]: + + $ makedumpfile /proc/kcore vmcore1 + get_mem_section: Could not validate mem_section. + get_mm_sparsemem: Can't get the address of mem_section. + + makedumpfile Failed. + +Let's check if the phys_start of the segment is a valid physical +address to fix this problem. + +[1] https://bugzilla.redhat.com/show_bug.cgi?id=1965267 + +Reported-by: Xiaoying Yan +Signed-off-by: Coiby Xu +--- + elf_info.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/makedumpfile-1.6.9/elf_info.c b/makedumpfile-1.6.9/elf_info.c +index e8affb7..bc24083 100644 +--- a/makedumpfile-1.6.9/elf_info.c ++++ b/makedumpfile-1.6.9/elf_info.c +@@ -628,7 +628,7 @@ get_max_paddr(void) + + for (i = 0; i < num_pt_loads; i++) { + pls = &pt_loads[i]; +- if (max_paddr < pls->phys_end) ++ if (pls->phys_start != NOT_PADDR && max_paddr < pls->phys_end) + max_paddr = pls->phys_end; + } + return max_paddr; +-- +2.29.2 + diff --git a/kexec-tools.spec b/kexec-tools.spec index ca2e30c..5aeda5a 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -101,6 +101,7 @@ Requires: systemd-udev%{?_isa} # Patches 601 onward are generic patches # Patch601: ./kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch +Patch602: ./kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -117,6 +118,7 @@ tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} %patch601 -p1 +%patch602 -p1 %ifarch ppc %define archdef ARCH=ppc From 50bb8b701f90a614849788bd01e9b005d159541e Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Tue, 22 Jun 2021 21:30:27 +0800 Subject: [PATCH 068/454] check for invalid physical address of /proc/kcore when making ELF dumpfile Backport from upstream. commit 9a6f589d99dcef114c89fde992157f5467028c8f Author: Tao Liu Date: Fri Jun 18 18:28:04 2021 +0800 [PATCH] check for invalid physical address of /proc/kcore when making ELF dumpfile Previously when executing makedumpfile with -E option against /proc/kcore, makedumpfile will fail: # makedumpfile -E -d 31 /proc/kcore kcore.dump ... write_elf_load_segment: Can't convert physaddr(ffffffffffffffff) to an offset. makedumpfile Failed. It's because /proc/kcore contains PT_LOAD program headers which have physaddr (0xffffffffffffffff). With -E option, makedumpfile will try to convert the physaddr to an offset and fails. Skip the PT_LOAD program headers which have such physaddr. Signed-off-by: Tao Liu Signed-off-by: Kazuhito Hagio Signed-off-by: Tao Liu Acked-by: Kairui Song --- ...-proc-kcore-when-making-ELF-dumpfile.patch | 43 +++++++++++++++++++ kexec-tools.spec | 2 + 2 files changed, 45 insertions(+) create mode 100644 kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch diff --git a/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch b/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch new file mode 100644 index 0000000..8cf780c --- /dev/null +++ b/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch @@ -0,0 +1,43 @@ +From 9a6f589d99dcef114c89fde992157f5467028c8f Mon Sep 17 00:00:00 2001 +From: Tao Liu +Date: Fri, 18 Jun 2021 18:28:04 +0800 +Subject: [PATCH] check for invalid physical address of /proc/kcore + when making ELF dumpfile + +Previously when executing makedumpfile with -E option against +/proc/kcore, makedumpfile will fail: + + # makedumpfile -E -d 31 /proc/kcore kcore.dump + ... + write_elf_load_segment: Can't convert physaddr(ffffffffffffffff) to an offset. + + makedumpfile Failed. + +It's because /proc/kcore contains PT_LOAD program headers which have +physaddr (0xffffffffffffffff). With -E option, makedumpfile will +try to convert the physaddr to an offset and fails. + +Skip the PT_LOAD program headers which have such physaddr. + +Signed-off-by: Tao Liu +Signed-off-by: Kazuhito Hagio +--- + makedumpfile.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/makedumpfile-1.6.9/makedumpfile.c b/makedumpfile-1.6.9/makedumpfile.c +index 894c88e..fcb571f 100644 +--- a/makedumpfile-1.6.9/makedumpfile.c ++++ b/makedumpfile-1.6.9/makedumpfile.c +@@ -7764,7 +7764,7 @@ write_elf_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_page) + if (!get_phdr_memory(i, &load)) + return FALSE; + +- if (load.p_type != PT_LOAD) ++ if (load.p_type != PT_LOAD || load.p_paddr == NOT_PADDR) + continue; + + off_memory= load.p_offset; +-- +2.29.2 + diff --git a/kexec-tools.spec b/kexec-tools.spec index 5aeda5a..f14b02f 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -102,6 +102,7 @@ Requires: systemd-udev%{?_isa} # Patch601: ./kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch Patch602: ./kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch +Patch603: ./kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -119,6 +120,7 @@ tar -z -x -v -f %{SOURCE19} %patch601 -p1 %patch602 -p1 +%patch603 -p1 %ifarch ppc %define archdef ARCH=ppc From 03f9b91351fcd245e8d9327c38de296f818ad115 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 28 Jun 2021 18:37:10 +0800 Subject: [PATCH 069/454] check the existence of /sys/bus/ccwgroup/devices before trying to find online network device /sys/bus/ccwgroup/devices doesn't exist for non-s390x machines which leads to the warning "find: '/sys/bus/ccwgroup/devices': No such file or directory". This warning can be eliminated by checking the existence of "/sys/bus/ccwgroup/devices" beforehand. Fixes: commit 7d472515688fb330eee76dac1c39ae628398f757 ("Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet") Reported-by: Ruowen Qin BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1974618 Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 35a961a..d9607d7 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -467,7 +467,9 @@ kdump_setup_vlan() { find_online_znet_device() { local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" local NETWORK_DEVICES d ifname ONLINE - NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR -type l) + + [ ! -d "$CCWGROUPBUS_DEVICEDIR" ] && return + NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) for d in $NETWORK_DEVICES do read ONLINE < $d/online From ad6f60d70df5306380c83fd1ebbd0a637ef993f1 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 28 Jun 2021 18:37:11 +0800 Subject: [PATCH 070/454] fix format issue in find_online_znet_device Change spaces to tab to fix alignment issue. Fixes: commit 7d472515688fb330eee76dac1c39ae628398f757 ("Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet") Signed-off-by: Coiby Xu Acked-by: Kairui Song --- dracut-module-setup.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index d9607d7..9b0f432 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -465,29 +465,29 @@ kdump_setup_vlan() { # code reaped from the list_configured function of # https://github.com/hreinecke/s390-tools/blob/master/zconf/znetconf find_online_znet_device() { - local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" - local NETWORK_DEVICES d ifname ONLINE + local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" + local NETWORK_DEVICES d ifname ONLINE [ ! -d "$CCWGROUPBUS_DEVICEDIR" ] && return - NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) + NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) for d in $NETWORK_DEVICES do - read ONLINE < $d/online - if [ $ONLINE -ne 1 ]; then - continue - fi - # determine interface name, if there (only for qeth and if - # device is online) - if [ -f $d/if_name ] - then - read ifname < $d/if_name - elif [ -d $d/net ] - then - ifname=$(ls $d/net/) - fi - [ -n "$ifname" ] && break - done - echo -n "$ifname" + read ONLINE < $d/online + if [ $ONLINE -ne 1 ]; then + continue + fi + # determine interface name, if there (only for qeth and if + # device is online) + if [ -f $d/if_name ] + then + read ifname < $d/if_name + elif [ -d $d/net ] + then + ifname=$(ls $d/net/) + fi + [ -n "$ifname" ] && break + done + echo -n "$ifname" } # setup s390 znet cmdline From c4749f9c57ea8b2d3eb5208cf1e8fd6df604b9f8 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 29 Jun 2021 21:23:56 +0800 Subject: [PATCH 071/454] Release 2.0.22-4 Signed-off-by: Kairui Song --- kexec-tools.spec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index f14b02f..e4f0b02 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.22 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -360,6 +360,13 @@ done %endif %changelog +* Tue Jun 29 2021 Kairui Song - 2.0.22-4 +* fix format issue in find_online_znet_device +* check the existence of /sys/bus/ccwgroup/devices before trying to find online network device +* check for invalid physical address of /proc/kcore when making ELF dumpfile +* check for invalid physical address of /proc/kcore when finding max_paddr +* Increase SECTION_MAP_LAST_BIT to 5 + * Sun Jun 20 2021 Kairui Song - 2.0.22-3 - selftest: Make test_base_image depends on EXTRA_RPMS - selftest: fix the error of misplacing double quotes From fa9201b2400565aca8165b9cd0a5151f1f94c7be Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Wed, 23 Jun 2021 20:06:48 +0530 Subject: [PATCH 072/454] fadump: isolate fadump initramfs image within the default one In case of fadump, the initramfs image has to be built to boot into the production environment as well as to offload the active crash dump to the specified dump target (for boot after crash). As the same image would be used for both boot scenarios, it could not be built optimally while accommodating both cases. Use --include to include the initramfs image built for offloading active crash dump to the specified dump target. Also, introduce a new out-of-tree dracut module (99zz-fadumpinit) that installs a customized init program while moving the default /init to /init.dracut. This customized init program is leveraged to isolate fadump image within the default initramfs image by kicking off default boot process (exec /init.dracut) for regular boot scenario and activating fadump initramfs image, if the system is booting after a crash. If squash is available, ensure default initramfs image is also built with squash module to reduce memory consumption in capture kernel. Signed-off-by: Hari Bathini Signed-off-by: Kairui Song Acked-by: Kairui Song --- dracut-fadump-init-fadump.sh | 44 +++++++++++++++++++++++++ dracut-fadump-module-setup.sh | 23 ++++++++++++++ dracut-module-setup.sh | 16 ++-------- kdump-lib.sh | 10 ++++++ kdumpctl | 22 +++---------- kexec-tools.spec | 14 ++++++++ mkdumprd | 5 +++ mkfadumprd | 60 +++++++++++++++++++++++++++++++++++ 8 files changed, 162 insertions(+), 32 deletions(-) create mode 100755 dracut-fadump-init-fadump.sh create mode 100644 dracut-fadump-module-setup.sh create mode 100644 mkfadumprd diff --git a/dracut-fadump-init-fadump.sh b/dracut-fadump-init-fadump.sh new file mode 100755 index 0000000..5468d99 --- /dev/null +++ b/dracut-fadump-init-fadump.sh @@ -0,0 +1,44 @@ +#!/bin/sh +export PATH=/usr/bin:/usr/sbin +export SYSTEMD_IN_INITRD=lenient + +[ -e /proc/mounts ] || + (mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc) + +grep -q '^sysfs /sys sysfs' /proc/mounts || + (mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys) + +grep -q '^none / ' /proc/mounts || grep -q '^rootfs / ' /proc/mounts && ROOTFS_IS_RAMFS=1 + +if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then + mkdir /newroot + mount -t ramfs ramfs /newroot + + if [ $ROOTFS_IS_RAMFS ]; then + for FILE in $(ls -A /fadumproot/); do + mv /fadumproot/$FILE /newroot/ + done + exec switch_root /newroot /init + else + mkdir /newroot/sys /newroot/proc /newroot/oldroot + mount --move /proc /newroot/proc + mount --move /sys /newroot/sys + cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr /fadumproot/. /newroot/ + cd /newroot && pivot_root . oldroot + + loop=1 + while [ $loop ]; do + unset loop + while read -r _ mp _; do + case $mp in + /oldroot/*) umount "$mp" && loop=1 ;; + esac + done /dev/null || return 1 - else - modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1 - fi - done - } - - if is_squash_available && ! is_fadump_capable; then + if is_squash_available; then add_opt_module squash else dwarning "Required modules to build a squashed kdump image is missing!" @@ -1087,7 +1077,5 @@ install() { ${initdir}/etc/lvm/lvm.conf &>/dev/null # Save more memory by dropping switch root capability - if ! is_fadump_capable; then - dracut_no_switch_root - fi + dracut_no_switch_root } diff --git a/kdump-lib.sh b/kdump-lib.sh index 27741fb..8e618f8 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -19,6 +19,16 @@ is_fadump_capable() return 1 } +is_squash_available() { + for kmodule in squashfs overlay loop; do + if [ -z "$KDUMP_KERNELVER" ]; then + modprobe --dry-run $kmodule &>/dev/null || return 1 + else + modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1 + fi + done +} + perror_exit() { derror "$@" exit 1 diff --git a/kdumpctl b/kdumpctl index 978dae5..26247d1 100755 --- a/kdumpctl +++ b/kdumpctl @@ -8,6 +8,7 @@ KEXEC_ARGS="" KDUMP_CONFIG_FILE="/etc/kdump.conf" KDUMP_LOG_PATH="/var/log" MKDUMPRD="/sbin/mkdumprd -f" +MKFADUMPRD="/sbin/mkfadumprd" DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" SAVE_PATH=/var/crash SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" @@ -104,25 +105,10 @@ save_core() rebuild_fadump_initrd() { - local target_initrd_tmp - - # this file tells the initrd is fadump enabled - touch /tmp/fadump.initramfs - target_initrd_tmp="$TARGET_INITRD.tmp" - ddebug "rebuild fadump initrd: $target_initrd_tmp $DEFAULT_INITRD_BAK $KDUMP_KERNELVER" - $MKDUMPRD $target_initrd_tmp --rebuild $DEFAULT_INITRD_BAK --kver $KDUMP_KERNELVER \ - -i /tmp/fadump.initramfs /etc/fadump.initramfs - if [ $? != 0 ]; then - derror "mkdumprd: failed to rebuild initrd with fadump support" - rm -f /tmp/fadump.initramfs + if ! $MKFADUMPRD "$DEFAULT_INITRD_BAK" "$TARGET_INITRD" --kver "$KDUMP_KERNELVER"; then + derror "mkfadumprd: failed to make fadump initrd" return 1 fi - rm -f /tmp/fadump.initramfs - - # updating fadump initrd - ddebug "updating fadump initrd: $target_initrd_tmp $TARGET_INITRD" - mv $target_initrd_tmp $TARGET_INITRD - sync return 0 } @@ -612,7 +598,7 @@ check_rebuild() #in case of fadump mode, check whether the default/target #initrd is already built with dump capture capability if [ "$DEFAULT_DUMP_MODE" == "fadump" ]; then - capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE $TARGET_INITRD | grep ^kdumpbase$ | wc -l) + capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE $TARGET_INITRD | grep -e ^kdumpbase$ -e ^zz-fadumpinit$ | wc -l) fi fi diff --git a/kexec-tools.spec b/kexec-tools.spec index e4f0b02..8fed959 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -39,6 +39,7 @@ Source28: kdump-udev-throttler Source29: kdump.sysconfig.aarch64 Source30: 60-kdump.install Source31: kdump-logger.sh +Source32: mkfadumprd ####################################### # These are sources for mkdumpramfs @@ -54,6 +55,9 @@ Source107: dracut-kdump-emergency.target Source108: dracut-early-kdump.sh Source109: dracut-early-kdump-module-setup.sh +Source200: dracut-fadump-init-fadump.sh +Source201: dracut-fadump-module-setup.sh + Requires(post): systemd-units Requires(preun): systemd-units Requires(postun): systemd-units @@ -183,6 +187,7 @@ SYSCONFIG=$RPM_SOURCE_DIR/kdump.sysconfig.%{_target_cpu} install -m 644 $SYSCONFIG $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/kdump install -m 755 %{SOURCE7} $RPM_BUILD_ROOT/usr/sbin/mkdumprd +install -m 755 %{SOURCE32} $RPM_BUILD_ROOT/usr/sbin/mkfadumprd install -m 644 %{SOURCE8} $RPM_BUILD_ROOT%{_sysconfdir}/kdump.conf install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8 install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8 @@ -218,6 +223,7 @@ install -m 644 makedumpfile-%{mkdf_ver}/eppic_scripts/* $RPM_BUILD_ROOT/usr/shar %define remove_dracut_prefix() %(echo -n %1|sed 's/.*dracut-//g') %define remove_dracut_early_kdump_prefix() %(echo -n %1|sed 's/.*dracut-early-kdump-//g') +%define remove_dracut_fadump_prefix() %(echo -n %1|sed 's/.*dracut-fadump-//g') # deal with dracut modules mkdir -p -m755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase @@ -235,6 +241,13 @@ cp %{SOURCE108} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlyk cp %{SOURCE109} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump/%{remove_dracut_early_kdump_prefix %{SOURCE109}} chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump/%{remove_dracut_prefix %{SOURCE108}} chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump/%{remove_dracut_early_kdump_prefix %{SOURCE109}} +%ifarch ppc64 ppc64le +mkdir -p -m755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit +cp %{SOURCE200} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE200}} +cp %{SOURCE201} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE201}} +chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE200}} +chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE201}} +%endif %define dracutlibdir %{_prefix}/lib/dracut @@ -316,6 +329,7 @@ done /usr/sbin/makedumpfile %endif /usr/sbin/mkdumprd +/usr/sbin/mkfadumprd /usr/sbin/vmcore-dmesg %{_bindir}/* %{_datadir}/kdump diff --git a/mkdumprd b/mkdumprd index 6d699c3..89a160d 100644 --- a/mkdumprd +++ b/mkdumprd @@ -452,6 +452,11 @@ then add_dracut_arg "--add-drivers" \"$extra_modules\" fi +# TODO: The below check is not needed anymore with the introduction of +# 'zz-fadumpinit' module, that isolates fadump's capture kernel initrd, +# but still sysroot.mount unit gets generated based on 'root=' kernel +# parameter available in fadump case. So, find a way to fix that first +# before removing this check. if ! is_fadump_capable; then # The 2nd rootfs mount stays behind the normal dump target mount, # so it doesn't affect the logic of check_dump_fs_modified(). diff --git a/mkfadumprd b/mkfadumprd new file mode 100644 index 0000000..4af4ae6 --- /dev/null +++ b/mkfadumprd @@ -0,0 +1,60 @@ +#!/bin/bash --norc +# Generate an initramfs image that isolates dump capture capability within +# the default initramfs using zz-fadumpinit dracut module. + +if [ -f /etc/sysconfig/kdump ]; then + . /etc/sysconfig/kdump +fi + +[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut +. $dracutbasedir/dracut-functions.sh +. /lib/kdump/kdump-lib.sh +. /lib/kdump/kdump-logger.sh + +#initiate the kdump logger +if ! dlog_init; then + echo "mkfadumprd: failed to initiate the kdump logger." + exit 1 +fi + +readonly MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)" +[ -d "$MKFADUMPRD_TMPDIR" ] || perror_exit "mkfadumprd: mktemp -d -t mkfadumprd.XXXXXX failed." +trap ' + ret=$?; + [[ -d $MKFADUMPRD_TMPDIR ]] && rm --one-file-system -rf -- "$MKFADUMPRD_TMPDIR"; + exit $ret; + ' EXIT + +# clean up after ourselves no matter how we die. +trap 'exit 1;' SIGINT + +MKDUMPRD="/sbin/mkdumprd -f" +# Default boot initramfs to be rebuilt +REBUILD_INITRD="$1" && shift +TARGET_INITRD="$1" && shift +FADUMP_INITRD="$MKFADUMPRD_TMPDIR/fadump.img" + +### First build an initramfs with dump capture capability +# this file tells the initrd is fadump enabled +touch "$MKFADUMPRD_TMPDIR/fadump.initramfs" +ddebug "rebuild fadump initrd: $FADUMP_INITRD $DEFAULT_INITRD $KDUMP_KERNELVER" +if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs; then + perror_exit "mkfadumprd: failed to build image with dump capture support" +fi + +### Unpack the initramfs having dump capture capability +mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot" +if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$MKFADUMPRD_TMPDIR/fadump.img" && \ + popd > /dev/null); then + derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'" + exit 1 +fi + +### Pack it into the normal boot initramfs with zz-fadumpinit module +_dracut_isolate_args="--rebuild $REBUILD_INITRD --add zz-fadumpinit -i $MKFADUMPRD_TMPDIR/fadumproot /fadumproot" +if is_squash_available; then + _dracut_isolate_args="$_dracut_isolate_args --add squash" +fi +if ! dracut --force --quiet $_dracut_isolate_args $@ "$TARGET_INITRD"; then + perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability" +fi From bf6671b60de3e1a33cda0a814b1729090f12f349 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 25 Jun 2021 14:44:45 +0800 Subject: [PATCH 073/454] fadump: kdumpctl should check the modules used by the fadump initramfs After fadump embedded the fadump initramfs in the normal initramfs, kdumpctl will mistakenly rebuild the initramfs everytime. kdumpctl checks the hostonly-kernel-modules.txt file in initramfs to check if required drivers are included, but the normal initramfs is built in non-hostonly mode, so it doesn't have a hostonly-kernel-modules.txt file. The check will always fail. So let mkfadumprd make a copy of the hostonly-kernel-modules.txt in the fadump initramfs and let kdumpctl check that file instead. Signed-off-by: Kairui Song Acked-by: Hari Bathini --- kdumpctl | 8 ++++++-- mkfadumprd | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/kdumpctl b/kdumpctl index 26247d1..e4334c5 100755 --- a/kdumpctl +++ b/kdumpctl @@ -443,9 +443,13 @@ check_drivers_modified() # Include watchdog drivers if watchdog module is not omitted is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)" - [ -z "$_new_drivers" ] && return 0 - _old_drivers="$(lsinitrd $TARGET_INITRD -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')" + + if is_fadump_capable; then + _old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')" + else + _old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')" + fi ddebug "Modules required for kdump: '$_new_drivers'" ddebug "Modules included in old initramfs: '$_old_drivers'" diff --git a/mkfadumprd b/mkfadumprd index 4af4ae6..aecf2a8 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -44,14 +44,18 @@ fi ### Unpack the initramfs having dump capture capability mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot" -if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$MKFADUMPRD_TMPDIR/fadump.img" && \ +if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" && \ popd > /dev/null); then derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'" exit 1 fi ### Pack it into the normal boot initramfs with zz-fadumpinit module -_dracut_isolate_args="--rebuild $REBUILD_INITRD --add zz-fadumpinit -i $MKFADUMPRD_TMPDIR/fadumproot /fadumproot" +_dracut_isolate_args="--rebuild $REBUILD_INITRD --add zz-fadumpinit \ + -i $MKFADUMPRD_TMPDIR/fadumproot /fadumproot \ + -i $MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt + /usr/lib/dracut/fadump-kernel-modules.txt" + if is_squash_available; then _dracut_isolate_args="$_dracut_isolate_args --add squash" fi From 97930d3ccad5ce090d3160a5781549b081467655 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 28 Jun 2021 13:57:27 +0800 Subject: [PATCH 074/454] fadump-init: clean up mount points properly When running with squash module enabled for both initramfs, /dev and /run are also mounted by squash-init, so move them to newroot as well, else they might leak. Also pass `-d` to umount so loop devices (if used) will be force freed. Signed-off-by: Kairui Song Acked-by: Hari Bathini --- dracut-fadump-init-fadump.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dracut-fadump-init-fadump.sh b/dracut-fadump-init-fadump.sh index 5468d99..94a3751 100755 --- a/dracut-fadump-init-fadump.sh +++ b/dracut-fadump-init-fadump.sh @@ -20,9 +20,13 @@ if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,o done exec switch_root /newroot /init else - mkdir /newroot/sys /newroot/proc /newroot/oldroot - mount --move /proc /newroot/proc + mkdir /newroot/sys /newroot/proc /newroot/dev /newroot/run /newroot/oldroot + + grep -q '^devtmpfs /dev devtmpfs' /proc/mounts && mount --move /dev /newroot/dev + grep -q '^tmpfs /run tmpfs' /proc/mounts && mount --move /run /newroot/run mount --move /sys /newroot/sys + mount --move /proc /newroot/proc + cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr /fadumproot/. /newroot/ cd /newroot && pivot_root . oldroot @@ -31,11 +35,11 @@ if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,o unset loop while read -r _ mp _; do case $mp in - /oldroot/*) umount "$mp" && loop=1 ;; + /oldroot/*) umount -d "$mp" && loop=1 ;; esac done Date: Fri, 25 Jun 2021 03:42:19 +0800 Subject: [PATCH 075/454] Revert "kdump-lib.sh: Remove is_atomic" Now we need this helper again, for `reset-crashkernel` This reverts commit ff46cfb19e9bf944a114164e33203b1a532d35f6. Signed-off-by: Kairui Song Acked-by: Baoquan He --- kdump-lib.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 8e618f8..df0aa02 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -341,6 +341,11 @@ kdump_get_persistent_dev() { echo $(get_persistent_dev "$dev") } +is_atomic() +{ + grep -q "ostree" /proc/cmdline +} + is_ipv6_address() { echo $1 | grep -q ":" From 86130ec10fda37cc283f717eaacb56a4cbf76418 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 10 Jun 2021 13:06:22 +0800 Subject: [PATCH 076/454] kdumpctl: Add kdumpctl reset-crashkernel In newer kernel, crashkernel.default will contain the default crashkernel value of a kernel build. So introduce a new sub command to help user reset kernel crashkernel size to the default value. Signed-off-by: Kairui Song Acked-by: Baoquan He --- kdumpctl | 41 +++++++++++++++++++++++++++++++++++++++-- kdumpctl.8 | 9 +++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index e4334c5..c5b210c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1330,6 +1330,40 @@ do_estimate() { fi } +reset_crashkernel() { + local kernel=$1 entry crashkernel_default + local grub_etc_default="/etc/default/grub" + + [[ -z "$kernel" ]] && kernel=$(uname -r) + crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null) + + if [[ -z "$crashkernel_default" ]]; then + derror "$kernel doesn't have a crashkernel.default" + exit 1 + fi + + if is_atomic; then + if rpm-ostree kargs | grep -q "crashkernel="; then + rpm-ostree --replace="crashkernel=$crashkernel_default" + else + rpm-ostree --append="crashkernel=$crashkernel_default" + fi + else + entry=$(grubby --info ALL | grep "^kernel=.*$kernel") + entry=${entry#kernel=} + entry=${entry#\"} + entry=${entry%\"} + + if [[ -f "$grub_etc_default" ]]; then + sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$crashkernel_default\2/" "$grub_etc_default" + fi + + [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" + grubby --args "$crashkernel_default" --update-kernel "$entry" $zipl_arg + [[ $zipl_arg ]] && zipl > /dev/null + fi + } + if [ ! -f "$KDUMP_CONFIG_FILE" ]; then derror "Error: No kdump config file found!" exit 1 @@ -1388,8 +1422,11 @@ main () estimate) do_estimate ;; + reset-crashkernel) + reset_crashkernel "$2" + ;; *) - dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|propagate|showmem}" + dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}" exit 1 esac } @@ -1399,6 +1436,6 @@ single_instance_lock # To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call main. # So that fd isn't leaking when main is invoking a subshell. -(exec 9<&-; main $1) +(exec 9<&-; main "$@") exit $? diff --git a/kdumpctl.8 b/kdumpctl.8 index a32a972..74be062 100644 --- a/kdumpctl.8 +++ b/kdumpctl.8 @@ -49,6 +49,15 @@ Prints the size of reserved memory for crash kernel in megabytes. Estimate a suitable crashkernel value for current machine. This is a best-effort estimate. It will print a recommanded crashkernel value based on current kdump setup, and list some details of memory usage. +.TP +.I reset-crashkernel [KERNEL] +Reset crashkernel value to default value. kdumpctl will try to read +from /usr/lib/modules//crashkernel.default and reset specified +kernel's crashkernel cmdline value. If no kernel is +specified, will reset current running kernel's crashkernel value. +If /usr/lib/modules//crashkernel.default doesn't exist, will +simply exit return 1. + .SH "SEE ALSO" .BR kdump.conf (5), From 646364193597401a55eb2485ef7840bb5eef7d88 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 10 Jun 2021 13:06:23 +0800 Subject: [PATCH 077/454] Add a new hook: 92-crashkernel.install To track and manage kernel's crashkernel usage by kernel version, each kernel package will include a crashkernel.default containing the default `crashkernel=` value of that kernel. So we can use a hook to update the kernel cmdline of new installed kernel accordingly. Put it after all other grub boot loader setup hooks, so it can simply call grubby to modify the kernel cmdline. Signed-off-by: Kairui Song Acked-by: Baoquan He --- 92-crashkernel.install | 143 +++++++++++++++++++++++++++++++++++++++++ kexec-tools.spec | 4 ++ 2 files changed, 147 insertions(+) create mode 100755 92-crashkernel.install diff --git a/92-crashkernel.install b/92-crashkernel.install new file mode 100755 index 0000000..7613bc6 --- /dev/null +++ b/92-crashkernel.install @@ -0,0 +1,143 @@ +#!/usr/bin/bash + +COMMAND="$1" +KERNEL_VERSION="$2" +KDUMP_INITRD_DIR_ABS="$3" +KERNEL_IMAGE="$4" + +grub_etc_default="/etc/default/grub" + +ver_lt() { + [[ "$(echo -e "$1\n$2" | sort -V)" == $1$'\n'* ]] && [[ $1 != "$2" ]] +} + +# Read crashkernel= value in /etc/default/grub +get_grub_etc_ck() { + [[ -e $grub_etc_default ]] && \ + sed -n -e "s/^GRUB_CMDLINE_LINUX=.*\(crashkernel=[^\ \"]*\)[\ \"].*$/\1/p" $grub_etc_default +} + +# Read crashkernel.default value of specified kernel +get_ck_default() { + ck_file="/usr/lib/modules/$1/crashkernel.default" + [[ -f "$ck_file" ]] && cat "$ck_file" +} + +# Iterate installed kernels, find the kernel with the highest version that has a +# valid crashkernel.default file, exclude current installing/removing kernel +# +# $1: a string representing a crashkernel= cmdline. If given, will also check the +# content of crashkernel.default, only crashkernel.default with the same value will match +get_highest_ck_default_kver() { + for kernel in $(find /usr/lib/modules -maxdepth 1 -mindepth 1 -printf "%f\n" | sort --version-sort -r); do + [[ $kernel == "$KERNEL_VERSION" ]] && continue + [[ -s "/usr/lib/modules/$kernel/crashkernel.default" ]] || continue + + echo "$kernel" + return 0 + done + + return 1 +} + +set_grub_ck() { + sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$1\2/" "$grub_etc_default" +} + +# Set specified kernel's crashkernel cmdline value +set_kernel_ck() { + kernel=$1 + ck_cmdline=$2 + + entry=$(grubby --info ALL | grep "^kernel=.*$kernel") + entry=${entry#kernel=} + entry=${entry#\"} + entry=${entry%\"} + + if [[ -z "$entry" ]]; then + echo "$0: failed to find boot entry for kernel $kernel" + return 1 + fi + + [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" + grubby --args "$ck_cmdline" --update-kernel "$entry" $zipl_arg + [[ $zipl_arg ]] && zipl > /dev/null +} + +case "$COMMAND" in +add) + # - If current boot kernel is using default crashkernel value, update + # installing kernel's crashkernel value to its default value, + # - If intalling a higher version kernel, and /etc/default/grub's + # crashkernel value is using default value, update it to installing + # kernel's default value. + inst_ck_default=$(get_ck_default "$KERNEL_VERSION") + # If installing kernel doesn't have crashkernel.default, just exit. + [[ -z "$inst_ck_default" ]] && exit 0 + + boot_kernel=$(uname -r) + boot_ck_cmdline=$(sed -n -e "s/^.*\(crashkernel=\S*\).*$/\1/p" /proc/cmdline) + highest_ck_default_kver=$(get_highest_ck_default_kver) + highest_ck_default=$(get_ck_default "$highest_ck_default_kver") + + # Try update /etc/default/grub if present, else grub2-mkconfig could + # override crashkernel value. + grub_etc_ck=$(get_grub_etc_ck) + if [[ -n "$grub_etc_ck" ]]; then + if [[ -z "$highest_ck_default_kver" ]]; then + # None of installed kernel have a crashkernel.default, + # check for 'crashkernel=auto' in case of legacy kernel + [[ "$grub_etc_ck" == "crashkernel=auto" ]] && \ + set_grub_ck "$inst_ck_default" + else + # There is a valid crashkernel.default, check if installing kernel + # have a higher version and grub config is using default value + ver_lt "$highest_ck_default_kver" "$KERNEL_VERSION" && \ + [[ "$grub_etc_ck" == "$highest_ck_default" ]] && \ + [[ "$grub_etc_ck" != "$inst_ck_default" ]] && \ + set_grub_ck "$inst_ck_default" + fi + fi + + # Exit if crashkernel is not used in current cmdline + [[ -z $boot_ck_cmdline ]] && exit 0 + + # Get current boot kernel's default value + boot_ck_default=$(get_ck_default "$boot_kernel") + if [[ $boot_ck_cmdline == "crashkernel=auto" ]]; then + # Legacy RHEL kernel defaults to "auto" + boot_ck_default="$boot_ck_cmdline" + fi + + # If boot kernel doesn't have a crashkernel.default, check + # if it's using any installed kernel's crashkernel.default + if [[ -z $boot_ck_default ]]; then + [[ $(get_highest_ck_default_kver "$boot_ck_cmdline") ]] && boot_ck_default="$boot_ck_cmdline" + fi + + # If boot kernel is using a default crashkernel, update + # installing kernel's crashkernel to new default value + if [[ "$boot_ck_cmdline" != "$inst_ck_default" ]] && [[ "$boot_ck_cmdline" == "$boot_ck_default" ]]; then + set_kernel_ck "$KERNEL_VERSION" "$inst_ck_default" + fi + ;; + +remove) + # If grub default value is upgraded when this kernel was installed, try downgrade it + grub_etc_ck=$(get_grub_etc_ck) + [[ $grub_etc_ck ]] || exit 0 + + removing_ck_conf=$(get_ck_default "$KERNEL_VERSION") + [[ $removing_ck_conf ]] || exit 0 + + highest_ck_default_kver=$(get_highest_ck_default_kver) || exit 0 + highest_ck_default=$(get_ck_default "$highest_ck_default_kver") + [[ $highest_ck_default ]] || exit 0 + + if ver_lt "$highest_ck_default_kver" "$KERNEL_VERSION"; then + if [[ $grub_etc_ck == "$removing_ck_conf" ]] && [[ $grub_etc_ck != "$highest_ck_default" ]]; then + set_grub_ck "$highest_ck_default" + fi + fi + ;; +esac diff --git a/kexec-tools.spec b/kexec-tools.spec index 8fed959..9848c2d 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -40,6 +40,7 @@ Source29: kdump.sysconfig.aarch64 Source30: 60-kdump.install Source31: kdump-logger.sh Source32: mkfadumprd +Source33: 92-crashkernel.install ####################################### # These are sources for mkdumpramfs @@ -66,6 +67,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool +Requires: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext @@ -210,6 +212,7 @@ install -m 644 %{SOURCE15} $RPM_BUILD_ROOT%{_mandir}/man5/kdump.conf.5 install -m 644 %{SOURCE16} $RPM_BUILD_ROOT%{_unitdir}/kdump.service install -m 755 -D %{SOURCE22} $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh install -m 755 -D %{SOURCE30} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-kdump.install +install -m 755 -D %{SOURCE33} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/92-crashkernel.install %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile @@ -360,6 +363,7 @@ done %{_unitdir}/kdump.service %{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh %{_prefix}/lib/kernel/install.d/60-kdump.install +%{_prefix}/lib/kernel/install.d/92-crashkernel.install %doc News %license COPYING %doc TODO From 7dbbb4bb31b6311e1283d0f801a26e7b6409248e Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 25 Jun 2021 04:01:45 +0800 Subject: [PATCH 078/454] Add a crashkernel-howto.txt doc Signed-off-by: Kairui Song Acked-by: Baoquan He --- crashkernel-howto.txt | 204 ++++++++++++++++++++++++++++++++++++++++++ kexec-tools.spec | 3 + 2 files changed, 207 insertions(+) create mode 100644 crashkernel-howto.txt diff --git a/crashkernel-howto.txt b/crashkernel-howto.txt new file mode 100644 index 0000000..4abd090 --- /dev/null +++ b/crashkernel-howto.txt @@ -0,0 +1,204 @@ +Introduction +============ + +This document describes features the kexec-tools package provides for setting +and estimating the crashkernel value. + +Kdump lives in a pre-reserved chunk of memory, and the size of the reserved +memory is specified by the `crashkernel=` kernel parameter. It's hard to +estimate an accurate `crashkernel=` value, so it's always recommended to test +kdump after you updated the `crashkernel=` value or changed the dump target. + + +Default crashkernel value +========================= + +Latest kernel packages includes a `crashkernel.default` file installed in kernel +modules folder, available as: + + /usr/lib/modules//crashkernel.default + +The content of the file will be taken as the default value of 'crashkernel=', or +take this file as a reference for setting crashkernel value manually. + + +New installed system +==================== + +Anaconda is the OS installer which sets all the kernel boot cmdline on a new +installed system. If kdump is set enabled during Anaconda installation, Anaconda +will use the `crashkernel.default` file as the default `crashkernel=` value on +the new installed system. + +Users can also override the value during Anaconda installation manually. + + +Auto update of crashkernel boot parameter +========================================= + +Following context in this section assumes all kernel packages have a +`crashkernel.default` file bundled, which is true for the latest official kernel +packages. For kexec-tools behavior with a kernel that doesn't have a +`crashkernel.default` file, please refer to the “Custom Kernel” section of this +doc. + +When `crashkernel=` is using the default value, kexec-tools will need to update +the `crashkernel=` value of new installed kernels, since the default value may +change in new kernel packages. + +kexec-tools does so by adding a kernel installation hook, which gets triggered +every time a new kernel is installed, so kexec-tools can do necessary checks and +updates. + + +Supported Bootloaders +--------------------- + +This auto update only works with GRUB2 and ZIPL, as kexec-tools heavily depends +on `grubby`. If other boot loaders are used, the user will have to update the +`crashkernel=` value manually. + + +Updating kernel package +----------------------- + +When a new version of package kernel is released in the official repository, the +package will always come with a `crashkernel.default` file bundled. Kexec-tools +will act with following rules: + +If current boot kernel is using the default `crashkernel=` boot param value from +its `crashkernel.default` file, then kexec-tools will update new installed +kernel’s `crashkernel=` boot param using the value from the new installed +kernel’s `crashkernel.default` file. This ensures `crashkernel=` is always using +the latest default value. + +If current boot kernel's `crashkernel=` value is set to a non-default value, the +new installed kernel simply inherits this value. + +On systems using GRUB2 as the bootloader, each kernel has its own boot entry, +making it possible to set different `crashkernel=` boot param values for +different kernels. So kexec-tools won’t touch any already installed kernel's +boot param, only new installed kernel's `crashkernel=` boot param value will be +updated. + +But some utilities like `grub2-mkconfig` and `grubby` can override all boot +entry's boot params with the boot params value from the GRUB config file +`/etc/defaults/grub`, so kexec-tools will also update the GRUB config file in +case old `crashkernel=` value overrides new installed kernel’s boot param. + + +Downgrading kernel package +-------------------------- + +When upgrading a kernel package, kexec-tools may update the `crashkernel=` value +in GRUB2 config file to the new value. So when downgrading the kernel package, +kexec-tools will also try to revert that update by setting GRUB2 config file’s +`crashkernel=` value back to the default value in the older kernel package. This +will only occur when the GRUB2 config file is using the default `crashkernel=` +value. + + +Custom kernel +============= + +To make auto crashkernel update more robust, kexec-tools will try to keep +tracking the default 'crashkernel=` value with kernels that don’t have a +`crashkernel.default` file, such kernels are referred to as “custom kernel” in +this doc. This is only a best-effort support to make it easier debugging and +testing the system. + +When installing a custom kernel that doesn’t have a `crashkernel.default` file, +the `crashkernel=` value will be simply inherited from the current boot kernel. + +When installing a new official kernel package and current boot kernel is a +custom kernel, since the boot kernel doesn’t have a `crashkernel.default` file, +kexec-tools will iterate installed kernels and check if the boot kernel +inherited the default value from any other existing kernels’ +`crashkernel.default` file. If a matching `crashkernel.default` file is found, +kexec-tools will update the new installed kernel `crashkernel=` boot param using +the value from the new installed kernel’s `crashkernel.default` file, ensures +the auto crashkernel value update won’t break over one or two custom kernel +installations. + +It is possible that the auto crashkernel value update will fail when custom +kernels are used. One example is a custom kernel inheriting the default +`crashkernel=` value from an older official kernel package, but later that +kernel package is uninstalled. So when booted with the custom kernel, +kexec-tools can't determine if the boot kernel is inheriting a default +`crashkernel=` value from any official build. In such a case, please refer to +the "Reset crashkernel to default value" section of this doc. + + +Reset crashkernel to default value +================================== + +kexec-tools only perform the auto update of crashkernel value when it can +confirm the boot kernel's crashkernel value is using its corresponding default +value or inherited from any installed kernel. + +kexec-tools may fail to determine if the boot kernel is using default +crashkernel value in some use cases: +- kexec-tools package is absent during a kernel package upgrade, and the new + kernel package’s `crashkernel.default` value has changed. +- Custom kernel is used and the kernel it inherits `crashkernel=` value from is + uninstalled. + +So it's recommended to reset the crashkernel value if users have uninstalled +kexec-tools or using a custom kernel. + +Reset using kdumpctl +-------------------- + +To make it easier to reset the `crashkernel=` kernel cmdline to this default +value properly, `kdumpctl` also provides a sub-command: + + `kdumpctl reset-crashkernel []` + +This command will read from the `crashkernel.default` file and reset +bootloader's kernel cmdline to the default value. It will also update bootloader +config if the bootloader has a standalone config file. User will have to reboot +the machine after this command to make it take effect. + +Reset manually +-------------- + +To reset the crashkernel value manually, it's recommended to use utils like +`grubby`. A one liner script for resetting `crashkernel=` value of all installed +kernels to current boot kernel's crashkernel.default` is: + + grubby --update-kernel ALL --args "$(cat /usr/lib/modules/$(uname -r)/crashkernel.default)" + +Estimate crashkernel +==================== + +The best way to estimate a usable crashkernel value is by testing kdump +manually. And you can set crashkernel to a large value, then adjust the +crashkernel value to an acceptable value gradually. + +`kdumpctl` also provides a sub-command for doing rough estimating without +triggering kdump: + + `kdumpctl estimate` + +The output will be like this: + +``` + Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement + + Reserved crashkernel: 256M + Recommended crashkernel: 655M + + Kernel image size: 47M + Kernel modules size: 12M + Initramfs size: 19M + Runtime reservation: 64M + LUKS required size: 512M + Large modules: + xfs: 1892352 + nouveau: 2318336 + WARNING: Current crashkernel size is lower than recommended size 655M. +``` + +It will generate a summary report about the estimated memory consumption +of each component of kdump. The value may not be accurate enough, but +would be a good start for finding a suitable crashkernel value. diff --git a/kexec-tools.spec b/kexec-tools.spec index 9848c2d..98d39fe 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -41,6 +41,7 @@ Source30: 60-kdump.install Source31: kdump-logger.sh Source32: mkfadumprd Source33: 92-crashkernel.install +Source34: crashkernel-howto.txt ####################################### # These are sources for mkdumpramfs @@ -151,6 +152,7 @@ cp %{SOURCE11} . cp %{SOURCE21} . cp %{SOURCE26} . cp %{SOURCE27} . +cp %{SOURCE34} . make %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 @@ -372,6 +374,7 @@ done %doc fadump-howto.txt %doc kdump-in-cluster-environment.txt %doc live-image-kdump-howto.txt +%doc crashkernel-howto.txt %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 %{_libdir}/eppic_makedumpfile.so /usr/share/makedumpfile/ From 2603ba71878f73ffa0608cb9c855da398c4132c1 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 2 Jul 2021 03:27:05 +0800 Subject: [PATCH 079/454] Cleanup dead systemd services before start sysroot.mount When kdump failed due to initqueue timeout, the sysroot.mount and other serivces could be stuck in `start` but `dead` status: Example output of systemctl: dev-disk-by\x2duuid-530830d1\x2df2c7\x2d4c9a\x2d9a82\x2d148609097521.device loaded inactive dead start <... snip ...> squash-root.mount loaded active mounted /squash/root squash.mount loaded active mounted /squash sysroot.mount loaded inactive dead start /sysroot <... snip ...> dracut-cmdline.service loaded active exited dracut cmdline hook dracut-initqueue.service loaded activating start start dracut initqueue hook dracut-mount.service loaded inactive dead start dracut mount hook At this point calling `systemctl start sysroot.mount` will just hang as systemd will just wait for the services that are stuck in `start` status. So call `systemctl cancel` here to cancel all pending jobs and have a clean start for mounting sysroot. Signed-off-by: Kairui Song Acked-by: Coiby Xu --- kdump-lib-initramfs.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index ca6a825..4cd18e4 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -227,6 +227,8 @@ dump_to_rootfs() systemctl start dracut-initqueue fi + dinfo "Clean up dead systemd services" + systemctl cancel dinfo "Waiting for rootfs mount, will timeout after 90 seconds" systemctl start sysroot.mount From 231a75ac1b7a1126678499b7413c15ff756636bb Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 6 Jul 2021 10:35:39 +0800 Subject: [PATCH 080/454] Revert "Revert "x86_64: enable the kexec file load by default"" This reverts commit 073c30973cf45ce0cea7bfd2bb30c5449a041a54, i.e. re-enable the kexec file load by default since this dual signature issue no longer bothers Fedora 34. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- kdump.sysconfig.x86_64 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump.sysconfig.x86_64 b/kdump.sysconfig.x86_64 index 1285506..188ba3c 100644 --- a/kdump.sysconfig.x86_64 +++ b/kdump.sysconfig.x86_64 @@ -28,7 +28,7 @@ KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory # # Example: # KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" +KEXEC_ARGS="-s" #Where to find the boot image #KDUMP_BOOTDIR="/boot" From 7b7ddaba88af9bcbbcc3d219e1c7f00b3a61152d Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 2 Jul 2021 01:31:26 +0800 Subject: [PATCH 081/454] kdump-lib.sh: kdump_get_arch_recommend_size uses crashkernel.default The new `crashkernel.default` file in kernel package can be used as the ck_cmdline source. Also keep the legacy code so old kernel packages will still work. Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- kdump-lib.sh | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index df0aa02..4bd9751 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -952,31 +952,40 @@ get_recommend_size() } # return recommended size based on current system RAM size +# $1: kernel version, if not set, will defaults to `uname -r` kdump_get_arch_recommend_size() { - if ! [[ -r "/proc/iomem" ]] ; then + local kernel=$1 arch + + if ! [ -r "/proc/iomem" ] ; then echo "Error, can not access /proc/iomem." return 1 fi - arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr [:lower:] [:upper:]) - if [ $arch == "X86_64" ] || [ $arch == "S390X" ]; then - ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" - elif [ $arch == "AARCH64" ]; then - ck_cmdline="2G-:448M" - elif [ $arch == "PPC64LE" ]; then - if is_fadump_capable; then - ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" - else - ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" + [ -z "$kernel" ] && kernel=$(uname -r) + ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null) + + if [ -n "$ck_cmdline" ]; then + ck_cmdline=${ck_cmdline#crashkernel=} + else + arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]') + if [ "$arch" = "X86_64" ] || [ "$arch" = "S390X" ]; then + ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" + elif [ "$arch" = "AARCH64" ]; then + ck_cmdline="2G-:448M" + elif [ "$arch" = "PPC64LE" ]; then + if is_fadump_capable; then + ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" + else + ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" + fi fi fi ck_cmdline=$(echo $ck_cmdline | sed -e 's/-:/-102400T:/g') sys_mem=$(get_system_size) - result=$(get_recommend_size $sys_mem "$ck_cmdline") - echo $result - return 0 + + get_recommend_size "$sys_mem" "$ck_cmdline" } # Print all underlying crypt devices of a block device From c894022e9b95390c700bfaf59b5a29311c69b896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 1 Jun 2021 10:15:11 +0200 Subject: [PATCH 082/454] Remove references to systemd-sysv-convert Packaging guidelines have been amended to not require systemd for scriptlets, see https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_scriptlets. The comment duplicates what the macro contains. systemd-sysv-convert binary was removed in 2013, trying to call it is unlikely to succeed. chkconfig binary is provided by the chkconfig package, which is not in Requires. (And makes little sense to call nowadays anyway.) --- kexec-tools.spec | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 98d39fe..ad29bf9 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -60,9 +60,6 @@ Source109: dracut-early-kdump-module-setup.sh Source200: dracut-fadump-init-fadump.sh Source201: dracut-fadump-module-setup.sh -Requires(post): systemd-units -Requires(preun): systemd-units -Requires(postun): systemd-units Requires(pre): coreutils sed zlib Requires: dracut >= 050 Requires: dracut-network >= 050 @@ -72,7 +69,7 @@ Requires: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext -BuildRequires: systemd-units +BuildRequires: systemd-rpm-macros BuildRequires: automake autoconf libtool %ifarch %{ix86} x86_64 ppc64 ppc s390x ppc64le Obsoletes: diskdumputils netdump kexec-tools-eppic @@ -292,20 +289,8 @@ fi %systemd_postun_with_restart kdump.service %preun -# Package removal, not upgrade %systemd_preun kdump.service -%triggerun -- kexec-tools < 2.0.2-3 -# Save the current service runlevel info -# User must manually run systemd-sysv-convert --apply kdump -# to migrate them to systemd targets -/usr/bin/systemd-sysv-convert --save kdump >/dev/null 2>&1 ||: - -# Run these because the SysV package being removed won't do them -/sbin/chkconfig --del kdump >/dev/null 2>&1 || : -/bin/systemctl try-restart kdump.service >/dev/null 2>&1 || : - - %triggerin -- kernel-kdump touch %{_sysconfdir}/kdump.conf From bcd8d6a47b3a1daa7ffb62561b7288dbadab3e61 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 15 Jul 2021 03:08:28 +0800 Subject: [PATCH 083/454] kdumpctl: fix a typo Recommanded -> Recommended Signed-off-by: Kairui Song Acked-by: Coiby Xu --- kdumpctl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kdumpctl b/kdumpctl index c5b210c..9e4005f 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1243,7 +1243,7 @@ do_estimate() { local kdump_mods local -A large_mods local baseline - local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommanded_size + local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommended_size local size_mb=$(( 1024 * 1024 )) setup_initrd @@ -1301,13 +1301,13 @@ do_estimate() { estimated_size=$((kernel_size + mod_size + initrd_size + runtime_size + crypt_size)) if [[ $baseline_size -gt $estimated_size ]]; then - recommanded_size=$baseline_size + recommended_size=$baseline_size else - recommanded_size=$estimated_size + recommended_size=$estimated_size fi echo "Reserved crashkernel: $((reserved_size / size_mb))M" - echo "Recommanded crashkernel: $((recommanded_size / size_mb))M" + echo "Recommended crashkernel: $((recommended_size / size_mb))M" echo echo "Kernel image size: $((kernel_size / size_mb))M" echo "Kernel modules size: $((mod_size / size_mb))M" @@ -1325,8 +1325,8 @@ do_estimate() { done fi - if [[ $reserved_size -le $recommanded_size ]]; then - echo "WARNING: Current crashkernel size is lower than recommanded size $((recommanded_size / size_mb))M." + if [[ $reserved_size -le $recommended_size ]]; then + echo "WARNING: Current crashkernel size is lower than recommended size $((recommended_size / size_mb))M." fi } From 914a856c66410099d0e8747e900d097624a3eb60 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 16 Jul 2021 10:34:35 +0200 Subject: [PATCH 084/454] kdump.sysconfig.s390: Remove "prot_virt" from kdump kernel cmdline "prot_virt" enables the kernel to run Secure Execution virtual machines on s390. These virtual machines are isolated from the hypervisor and thus protected against tampering by a malicious host. Enabling "prot_virt" requires a minimum of ~2.5GB memory which exceeds what is typically reserved for the crashkernel. Thus remove "prot_virt" from the command line for the 2nd kernel to prevent it to run out-of-memory. For more discussions about this, see: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org/thread/QSRRNV4ALKXUJC2VM3US4Z2NSQRHVMXB/ Signed-off-by: Philipp Rudo Acked-by: Baoquan He --- kdump.sysconfig.s390x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump.sysconfig.s390x b/kdump.sysconfig.s390x index 439e462..234cfe9 100644 --- a/kdump.sysconfig.s390x +++ b/kdump.sysconfig.s390x @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE From 71b7a2f47c783b33965e8fc469dc44bda08cf458 Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Mon, 12 Jul 2021 15:33:03 +0530 Subject: [PATCH 085/454] kdump/ppc64: rebuild initramfs image after migration Dump capture initramfs needs rebuild after partition migration (LPM). Use servicelog notification mechanism to invoke kdump rebuild after migration. Signed-off-by: Hari Bathini Reviewed-by: Pingfan Liu Acked-by: Kairui Song --- kdump-migrate-action.sh | 8 ++++++++ kdump-restart.sh | 8 ++++++++ kexec-tools.spec | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100755 kdump-migrate-action.sh create mode 100644 kdump-restart.sh diff --git a/kdump-migrate-action.sh b/kdump-migrate-action.sh new file mode 100755 index 0000000..c516639 --- /dev/null +++ b/kdump-migrate-action.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +systemctl is-active kdump +if [ $? -ne 0 ]; then + exit 0 +fi + +/usr/lib/kdump/kdump-restart.sh diff --git a/kdump-restart.sh b/kdump-restart.sh new file mode 100644 index 0000000..a9ecfc1 --- /dev/null +++ b/kdump-restart.sh @@ -0,0 +1,8 @@ +#!/bin/bash +export PATH="$PATH:/usr/bin:/usr/sbin" + +exec >>/var/log/kdump-migration.log 2>&1 + +echo "kdump: Partition Migration detected. Rebuilding initramfs image to reload." +/usr/bin/kdumpctl rebuild +/usr/bin/kdumpctl reload diff --git a/kexec-tools.spec b/kexec-tools.spec index ad29bf9..7f88863 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -42,6 +42,8 @@ Source31: kdump-logger.sh Source32: mkfadumprd Source33: 92-crashkernel.install Source34: crashkernel-howto.txt +Source35: kdump-migrate-action.sh +Source36: kdump-restart.sh ####################################### # These are sources for mkdumpramfs @@ -60,6 +62,9 @@ Source109: dracut-early-kdump-module-setup.sh Source200: dracut-fadump-init-fadump.sh Source201: dracut-fadump-module-setup.sh +%ifarch ppc64 ppc64le +Requires(post): servicelog +%endif Requires(pre): coreutils sed zlib Requires: dracut >= 050 Requires: dracut-network >= 050 @@ -196,6 +201,10 @@ install -m 644 %{SOURCE25} $RPM_BUILD_ROOT%{_mandir}/man8/kdumpctl.8 install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh install -m 755 %{SOURCE23} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh install -m 755 %{SOURCE31} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-logger.sh +%ifarch ppc64 ppc64le +install -m 755 %{SOURCE35} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-migrate-action.sh +install -m 755 %{SOURCE36} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-restart.sh +%endif %ifnarch s390x install -m 755 %{SOURCE28} $RPM_BUILD_ROOT%{_udevrulesdir}/../kdump-udev-throttler %endif @@ -262,6 +271,13 @@ mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{d %systemd_post kdump.service touch /etc/kdump.conf + +ARCH=`uname -m` +if [ "$ARCH" == "ppc64" ] || [ "$ARCH" == "ppc64le" ] +then + servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin +fi + # This portion of the script is temporary. Its only here # to fix up broken boxes that require special settings # in /etc/sysconfig/kdump. It will be removed when From 7435ecf3c43c0d15dc103c964043facce4b21a37 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 21 Jul 2021 14:05:25 +0800 Subject: [PATCH 086/454] Update crashkernel-howto.txt Fix some grammar issues. Signed-off-by: Kairui Song --- crashkernel-howto.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crashkernel-howto.txt b/crashkernel-howto.txt index 4abd090..20f50e0 100644 --- a/crashkernel-howto.txt +++ b/crashkernel-howto.txt @@ -13,7 +13,7 @@ kdump after you updated the `crashkernel=` value or changed the dump target. Default crashkernel value ========================= -Latest kernel packages includes a `crashkernel.default` file installed in kernel +Latest kernel packages include a `crashkernel.default` file installed in kernel modules folder, available as: /usr/lib/modules//crashkernel.default @@ -25,12 +25,12 @@ take this file as a reference for setting crashkernel value manually. New installed system ==================== -Anaconda is the OS installer which sets all the kernel boot cmdline on a new -installed system. If kdump is set enabled during Anaconda installation, Anaconda +Anaconda is the OS installer which sets all the kernel boot cmdline on a newly +installed system. If kdump is enabled during Anaconda installation, Anaconda will use the `crashkernel.default` file as the default `crashkernel=` value on -the new installed system. +the newly installed system. -Users can also override the value during Anaconda installation manually. +Users can override the value during Anaconda installation manually. Auto update of crashkernel boot parameter From 660cf4ac03f29c42801725908cac156151159d2b Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 20 Jul 2021 13:41:08 +0800 Subject: [PATCH 087/454] Make `dump_to_rootfs` wait for 90s for real When `failure_action` is set to `dump_to_rootfs`, the message: "Waiting for rootfs mount, will timeout after 90 seconds" is actually wrong. Kdump will simply call `systemctl start sysroot.mount`, but the timeout value of sysroot.mount depends on the unit service and dracut parameters. And by default, dracut will set JobRunningTimeoutSec=0 and JobTimeoutSec=0 for the device units, which means it will wait forever. (see wait_for_dev function in dracut) For some devices, this can be fixed by setting rd.timeout=90. But when initqueue is set enabled during initramfs build, dracut will force set timeout for host devices to `0`. (see 99base/module-setup.sh). Depending on dracut / systemd can make things unpredictable and break as parameters or code change. To make things easy to understand and maintain, just call `systemctl` with `--no-block` params, and implement a standalone wait loop. Now `dump_to_rootfs` will actually wait for 90s then timeout. Signed-off-by: Kairui Song Acked-by: Coiby Xu --- kdump-lib-initramfs.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 4cd18e4..319f9a0 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -230,10 +230,20 @@ dump_to_rootfs() dinfo "Clean up dead systemd services" systemctl cancel dinfo "Waiting for rootfs mount, will timeout after 90 seconds" - systemctl start sysroot.mount + systemctl start --no-block sysroot.mount + + _loop=0 + while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do + sleep 1 + _loop=$((_loop + 1)) + done + + if ! is_mounted /sysroot; then + derror "Failed to mount rootfs" + return + fi ddebug "NEWROOT=$NEWROOT" - dump_fs $NEWROOT } From b2bbb54d897959b1a6de6841ff397d6ec9565a12 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 15 Jul 2021 09:18:33 +0800 Subject: [PATCH 088/454] Check the existence of /sys/bus/ccwgroup/devices/*/online beforehand On s390x KVM machines, the following errors would show when building kdump initramfs that dumps vmcore to a remote target, $ kdumpctl rebuild /usr/lib/dracut/modules.d/99kdumpbase/module-setup.sh: line 475: /sys/bus/ccwgroup/devices/online: No such file or directory /usr/lib/dracut/modules.d/99kdumpbase/module-setup.sh: line 476: [: -ne: unary operator expected This happens because s390x KVM machines use virtual network and /sys/bus/ccwgroup/devices/ exists but is empty. Fix it by check the existence of file "/sys/bus/ccwgroup/devices/*/online". Fixes: commit 7d472515688fb330eee76dac1c39ae628398f757 ("Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet") BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1982474 Reported-by: Jie Li Signed-off-by: Coiby Xu t Acked-by: Kairui Song --- dracut-module-setup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 8211d14..a1f33e8 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -462,6 +462,7 @@ find_online_znet_device() { NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) for d in $NETWORK_DEVICES do + [ ! -f "$d/online" ] && continue read ONLINE < $d/online if [ $ONLINE -ne 1 ]; then continue From 152cf5e46cddc49b716fb3fd5bf85dbf12a020cb Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Thu, 22 Jul 2021 09:42:58 +0000 Subject: [PATCH 089/454] - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 7f88863..6f421fa 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.22 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -382,6 +382,9 @@ done %endif %changelog +* Thu Jul 22 2021 Fedora Release Engineering - 2.0.22-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild + * Tue Jun 29 2021 Kairui Song - 2.0.22-4 * fix format issue in find_online_znet_device * check the existence of /sys/bus/ccwgroup/devices before trying to find online network device From 146f66262222e96bca47b691ed243fa5097aa55c Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Tue, 27 Jul 2021 23:59:48 +0530 Subject: [PATCH 090/454] kdump/ppc64: migration action registration clean up While kdump migration action is registered for LPM event, ensure it is cleared as appropriate to avoid duplicate/stale notification entries. Signed-off-by: Hari Bathini Acked-by: Kairui Song --- kexec-tools.spec | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 6f421fa..c042590 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -272,11 +272,10 @@ mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{d touch /etc/kdump.conf -ARCH=`uname -m` -if [ "$ARCH" == "ppc64" ] || [ "$ARCH" == "ppc64le" ] -then - servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin -fi +%ifarch ppc64 ppc64le +servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh +servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin +%endif # This portion of the script is temporary. Its only here # to fix up broken boxes that require special settings @@ -305,6 +304,9 @@ fi %systemd_postun_with_restart kdump.service %preun +%ifarch ppc64 ppc64le +servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh +%endif %systemd_preun kdump.service %triggerin -- kernel-kdump From 097059dedc987548742437bca6fd90793cf74c18 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 30 Jul 2021 14:40:45 +0800 Subject: [PATCH 091/454] Clear old crashkernl=auto in comment and doc Acked-by: Pingfan Liu Signed-off-by: Kairui Song --- fadump-howto.txt | 9 ++++++--- kdumpctl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fadump-howto.txt b/fadump-howto.txt index 433e9a6..bc87644 100644 --- a/fadump-howto.txt +++ b/fadump-howto.txt @@ -344,9 +344,12 @@ or OR # grubby --update-kernel=/boot/vmlinuz-`uname -r` --args="fadump=off" -If KDump is to be used as the dump capturing mechanism, update the crashkernel -parameter (Else, remove "crashkernel=" parameter too, using grubby): +Remove "crashkernel=" from kernel cmdline parameters: - # grubby --update-kernel=/boot/vmlinuz-$kver --args="crashkernl=auto" + # grubby --update-kernel=/boot/vmlinuz-`uname -r` --remove-args="crashkernel" + +If KDump is to be used as the dump capturing mechanism, reset the crashkernel parameter: + + # kdumpctl reset-crashkernel `uname -r` Reboot the system for the settings to take effect. diff --git a/kdumpctl b/kdumpctl index 9e4005f..c2f0b3f 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1262,7 +1262,7 @@ do_estimate() { baseline=$(( ${baseline%Y} * 1048576 )) fi - # The default value when using crashkernel=auto + # The default pre-reserved crashkernel value baseline_size=$((baseline * size_mb)) # Current reserved crashkernel size reserved_size=$(cat /sys/kernel/kexec_crash_size) From 7ddda7e6d0d5051321639c922c9aa117c869dcb5 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 18 Aug 2021 22:25:22 +0800 Subject: [PATCH 092/454] Remove hard requirement on grubby Downgrade to "Recommends:" as suggested by CoreOS team. Signed-off-by: Kairui Song Acked-by: Tao Liu --- kexec-tools.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index c042590..951c9d6 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -70,7 +70,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool -Requires: grubby +Recommends: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext From 6c390b70e847588271b7fc5e57091a36a7207f9e Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 20 Aug 2021 20:09:33 +0800 Subject: [PATCH 093/454] Release 2.0.22-6 Also fix a format error in changelog. Signed-off-by: Kairui Song --- kexec-tools.spec | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 951c9d6..58be768 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.22 -Release: 5%{?dist} +Release: 6%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -384,15 +384,37 @@ done %endif %changelog +* Fri Aug 20 2021 Kairui Song - 2.0.22-6 +- Remove hard requirement on grubby +- Clear old crashkernl=auto in comment and doc +- kdump/ppc64: migration action registration clean up +- Check the existence of /sys/bus/ccwgroup/devices/*/online beforehand +- Make `dump_to_rootfs` wait for 90s for real +- Update crashkernel-howto.txt +- kdump/ppc64: rebuild initramfs image after migration +- kdump.sysconfig.s390: Remove "prot_virt" from kdump kernel cmdline +- kdumpctl: fix a typo +- Remove references to systemd-sysv-convert +- kdump-lib.sh: kdump_get_arch_recommend_size uses crashkernel.default +- Revert "Revert "x86_64: enable the kexec file load by default"" +- Cleanup dead systemd services before start sysroot.mount +- Add a crashkernel-howto.txt doc +- Add a new hook: 92-crashkernel.install +- kdumpctl: Add kdumpctl reset-crashkernel +- Revert "kdump-lib.sh: Remove is_atomic" +- fadump-init: clean up mount points properly +- fadump: kdumpctl should check the modules used by the fadump initramfs +- fadump: isolate fadump initramfs image within the default one + * Thu Jul 22 2021 Fedora Release Engineering - 2.0.22-5 - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild * Tue Jun 29 2021 Kairui Song - 2.0.22-4 -* fix format issue in find_online_znet_device -* check the existence of /sys/bus/ccwgroup/devices before trying to find online network device -* check for invalid physical address of /proc/kcore when making ELF dumpfile -* check for invalid physical address of /proc/kcore when finding max_paddr -* Increase SECTION_MAP_LAST_BIT to 5 +- fix format issue in find_online_znet_device +- check the existence of /sys/bus/ccwgroup/devices before trying to find online network device +- check for invalid physical address of /proc/kcore when making ELF dumpfile +- check for invalid physical address of /proc/kcore when finding max_paddr +- Increase SECTION_MAP_LAST_BIT to 5 * Sun Jun 20 2021 Kairui Song - 2.0.22-3 - selftest: Make test_base_image depends on EXTRA_RPMS From 5270d40dd0b690d4be628f937e508cdc80dab1d9 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Tue, 31 Aug 2021 16:07:51 -0700 Subject: [PATCH 094/454] Don't exit 1 from 92-crashkernel.install if zipl is absent (#1993505) At least, this is a plausible suspect for #1993505 - thanks to @kevin for identifying it - and fixing it should be safe and correct, so we may as well do it and see if it helps. --- 92-crashkernel.install | 2 +- kexec-tools.spec | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/92-crashkernel.install b/92-crashkernel.install index 7613bc6..de5b2fb 100755 --- a/92-crashkernel.install +++ b/92-crashkernel.install @@ -61,7 +61,7 @@ set_kernel_ck() { [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" grubby --args "$ck_cmdline" --update-kernel "$entry" $zipl_arg - [[ $zipl_arg ]] && zipl > /dev/null + [[ $zipl_arg ]] && zipl > /dev/null ||: } case "$COMMAND" in diff --git a/kexec-tools.spec b/kexec-tools.spec index 58be768..7db9f9c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.22 -Release: 6%{?dist} +Release: 7%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -384,6 +384,9 @@ done %endif %changelog +* Tue Aug 31 2021 Adam Williamson - 2.0.22-7 +- Don't exit 1 from 92-crashkernel.install if zipl is absent (#1993505) + * Fri Aug 20 2021 Kairui Song - 2.0.22-6 - Remove hard requirement on grubby - Clear old crashkernl=auto in comment and doc From bcb1176ec6f17538ffff94d2fbd21579938c3c05 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 30 Jul 2021 01:08:30 +0800 Subject: [PATCH 095/454] Add a .editorconfig file EditorConfig file is helpful for tools like `shfmt`, also could be a hint for code styling. The code style spec used in this new added .editorconfig file is generated based on existing code style. Following commits will make mkfadumprd, mkdumprd, kdumpctl, kdump-lib.sh, and *-module-setup.sh only be used in first kernel, so use bash syntax for these scripts. Other scripts will use sh syntax for better POSIX compatibility. Signed-off-by: Kairui Song Acked-by: Pingfan Liu Acked-by: Philipp Rudo Signed-off-by: Kairui Song --- .editorconfig | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bd8fc8c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,32 @@ +# EditorConfig configuration for kexec-tools +# http://EditorConfig.org + +# Top-most EditorConfig file +root = true + +# Default code style for kexec-tools scripts +[*] +end_of_line = lf +shell_variant = posix +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = tab +indent_size = 1 +switch_case_indent = false +function_next_line = true +binary_next_line = false +space_redirects = true + +# Some scripts will only run with bash +[{mkfadumprd,mkdumprd,kdumpctl}] +shell_variant = bash + +# Use dracut code style for *-module-setup.sh +[*-module-setup.sh] +shell_variant = bash +indent_style = space +indent_size = 4 +switch_case_indent = true +function_next_line = false +binary_next_line = true +space_redirects = true From a0282ab22c4e61294346c8ab9c42ab87b8bdfbb0 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 3 Aug 2021 19:49:51 +0800 Subject: [PATCH 096/454] kdump-lib.sh: add a config format and read helper Add a helper `kdump_read_conf` to replace read_strip_comments. `kdump_read_conf` does a few more things: - remove trailing spaces. - format the content, remove duplicated spaces between name and value. - read from KDUMP_CONFIG_FILE (/etc/kdump.conf) directly, avoid pasting "/etc/kdump.conf" path everywhere in the code. - check if config file exists, just in case. Also unify the environmental variable, now KDUMP_CONFIG_FILE stands for the default config location. This helps avoid some shell pitfalls about spaces when reading config. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 10 +++++----- dracut-module-setup.sh | 5 +++-- kdump-lib-initramfs.sh | 3 +-- kdump-lib.sh | 11 ++++++----- kdumpctl | 7 +++---- mkdumprd | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 3e65c44..3c165b3 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -246,10 +246,10 @@ get_host_ip() return 0 } -read_kdump_conf() +read_kdump_confs() { - if [ ! -f "$KDUMP_CONF" ]; then - derror "$KDUMP_CONF not found" + if [ ! -f "$KDUMP_CONFIG_FILE" ]; then + derror "$KDUMP_CONFIG_FILE not found" return fi @@ -278,7 +278,7 @@ read_kdump_conf() add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val" ;; esac - done <<< "$(read_strip_comments $KDUMP_CONF)" + done <<< "$(kdump_read_conf)" } fence_kdump_notify() @@ -288,7 +288,7 @@ fence_kdump_notify() fi } -read_kdump_conf +read_kdump_confs fence_kdump_notify get_host_ip diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index a1f33e8..ff9f7fe 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -682,7 +682,8 @@ default_dump_target_install_conf() #install kdump.conf and what user specifies in kdump.conf kdump_install_conf() { local _opt _val _pdev - (read_strip_comments /etc/kdump.conf) > ${initdir}/tmp/$$-kdump.conf + + kdump_read_conf > "${initdir}/tmp/$$-kdump.conf" while read _opt _val; do @@ -711,7 +712,7 @@ kdump_install_conf() { dracut_install "${_val%%[[:blank:]]*}" ;; esac - done <<< "$(read_strip_comments /etc/kdump.conf)" + done <<< "$(kdump_read_conf)" kdump_install_pre_post_conf diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 319f9a0..50443e5 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -16,7 +16,6 @@ SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" KDUMP_SCRIPT_DIR="/kdumpscripts" DD_BLKSIZE=512 FINAL_ACTION="systemctl reboot -f" -KDUMP_CONF="/etc/kdump.conf" KDUMP_PRE="" KDUMP_POST="" NEWROOT="/sysroot" @@ -93,7 +92,7 @@ get_kdump_confs() esac ;; esac - done <<< "$(read_strip_comments $KDUMP_CONF)" + done <<< "$(kdump_read_conf)" if [ -z "$CORE_COLLECTOR" ]; then CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" diff --git a/kdump-lib.sh b/kdump-lib.sh index 4bd9751..841740b 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -7,6 +7,7 @@ DEFAULT_PATH="/var/crash/" FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" +KDUMP_CONFIG_FILE="/etc/kdump.conf" is_fadump_capable() { @@ -80,12 +81,12 @@ strip_comments() echo $@ | sed -e 's/\(.*\)#.*/\1/' } -# Read from kdump config file stripping all comments -read_strip_comments() +# Read kdump config in well formatted style +kdump_read_conf() { - # 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 + # Following steps are applied in order: strip trailing comment, strip trailing space, + # strip heading space, match non-empty line, remove duplicated spaces between conf name and value + [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE } # Check if fence kdump is configured in Pacemaker cluster diff --git a/kdumpctl b/kdumpctl index c2f0b3f..5d9420d 100755 --- a/kdumpctl +++ b/kdumpctl @@ -5,7 +5,6 @@ KDUMP_KERNELVER="" KDUMP_KERNEL="" KDUMP_COMMANDLINE="" KEXEC_ARGS="" -KDUMP_CONFIG_FILE="/etc/kdump.conf" KDUMP_LOG_PATH="/var/log" MKDUMPRD="/sbin/mkdumprd -f" MKFADUMPRD="/sbin/mkfadumprd" @@ -272,7 +271,7 @@ check_config() return 1 fi _opt_rec[$config_opt]="$config_val" - done <<< "$(read_strip_comments $KDUMP_CONFIG_FILE)" + done <<< "$(kdump_read_conf)" check_failure_action_config || return 1 check_final_action_config || return 1 @@ -731,7 +730,7 @@ check_ssh_config() *) ;; esac - done <<< "$(read_strip_comments $KDUMP_CONFIG_FILE)" + done <<< "$(kdump_read_conf)" #make sure they've configured kdump.conf for ssh dumps local SSH_TARGET=`echo -n $DUMP_TARGET | sed -n '/.*@/p'` @@ -1362,7 +1361,7 @@ reset_crashkernel() { grubby --args "$crashkernel_default" --update-kernel "$entry" $zipl_arg [[ $zipl_arg ]] && zipl > /dev/null fi - } +} if [ ! -f "$KDUMP_CONFIG_FILE" ]; then derror "Error: No kdump config file found!" diff --git a/mkdumprd b/mkdumprd index 89a160d..d554511 100644 --- a/mkdumprd +++ b/mkdumprd @@ -443,7 +443,7 @@ do *) ;; esac -done <<< "$(read_strip_comments $conf_file)" +done <<< "$(kdump_read_conf)" handle_default_dump_target From 09ccf88405793220af640c5317cbadb71cf03d36 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 16 Aug 2021 23:25:14 +0800 Subject: [PATCH 097/454] kdump-lib.sh: add a config value retrive helper Add a helper kdump_get_conf_val to replace get_option_value. It can help cover more corner cases in the code, like when there are multiple spaces in config file, config value separated by a tab, heading spaces, or trailing comments. And this uses "sed group command" and "sed hold buffer", make it much faster than previous `grep | tail -1`. This helper is supposed to provide a universal way for kexec-tools scripts to read in config value. Currently, different scripts are reading the config in many different fragile ways. For example, following codes are found in kexec-tools script code base: 1. grep ^force_rebuild $KDUMP_CONFIG_FILE echo $_force_rebuild | cut -d' ' -f2 2. grep ^kdump_post $KDUMP_CONFIG_FILE | cut -d\ -f2 3. awk '/^sshkey/ {print $2}' $conf_file 4. grep ^path $KDUMP_CONFIG_FILE | cut -d' ' -f2- 1, 2, and 4 will fail if the space is replaced by, e.g. a tab 1 and 2 might fail if there are multiple spaces between config name and config value: "kdump_post /var/crash/scripts/kdump-post.sh" A space will be read instead of config value. 1, 2, 3 will fail if there are space in file path, like: "kdump_post /var/crash/scripts dir/kdump-post.sh" 4 will fail if there are trailing comments: "path /var/crash # some comment here" And all will fail if there are heading space, " path /var/crash" And all will most likely cause problems if the config file contains the same option more than once. And all of them are slower than the new sed call. Old get_option_value is also very slow and doesn't handle heading space. Although we never claim to support heading space or tailing comments before, it's harmless to be more robust on config reading, and many conf files in /etc support heading spaces. And have a faster and safer config reading helper makes it easier to clean up the code. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 4 ++-- kdump-lib.sh | 20 +++++++++----------- kdumpctl | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index ff9f7fe..53abdc7 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -938,7 +938,7 @@ get_generic_fence_kdump_nodes() { local filtered local nodes - nodes=$(get_option_value "fence_kdump_nodes") + nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in ${nodes}; do # Skip its own node name if is_localhost $node; then @@ -999,7 +999,7 @@ kdump_install_random_seed() { } kdump_install_systemd_conf() { - local failure_action=$(get_option_value "failure_action") + local failure_action=$(kdump_get_conf_val "failure_action") # Kdump turns out to require longer default systemd mount timeout # than 1st kernel(90s by default), we use default 300s for kdump. diff --git a/kdump-lib.sh b/kdump-lib.sh index 841740b..b57457c 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -76,11 +76,6 @@ is_fs_dump_target() egrep -q "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf } -strip_comments() -{ - echo $@ | sed -e 's/\(.*\)#.*/\1/' -} - # Read kdump config in well formatted style kdump_read_conf() { @@ -89,6 +84,15 @@ kdump_read_conf() [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE } +# Retrieves config value defined in kdump.conf +# $1: config name, sed regexp compatible +kdump_get_conf_val() { + # For lines matching "^\s*$1\s+", remove matched part (config name including space), + # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. + [ -f "$KDUMP_CONFIG_FILE" ] && \ + sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE +} + # Check if fence kdump is configured in Pacemaker cluster is_pcs_fence_kdump() { @@ -322,12 +326,6 @@ get_kdump_mntpoint_from_target() echo $_mntpoint | tr -s "/" } -# get_option_value -# retrieves value of option defined in kdump.conf -get_option_value() { - strip_comments `grep "^$1[[:space:]]\+" /etc/kdump.conf | tail -1 | cut -d\ -f2-` -} - kdump_get_persistent_dev() { local dev="${1//\"/}" diff --git a/kdumpctl b/kdumpctl index 5d9420d..db3a301 100755 --- a/kdumpctl +++ b/kdumpctl @@ -961,7 +961,7 @@ check_fence_kdump_config() { local hostname=`hostname` local ipaddrs=`hostname -I` - local nodes=$(get_option_value "fence_kdump_nodes") + local nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in $nodes; do if [ "$node" = "$hostname" ]; then From ab1ef78aa25b7ae2e34e16a74712079653981e6b Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 01:18:48 +0800 Subject: [PATCH 098/454] kdump-lib.sh: use kdump_get_conf_val to read config values Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-lib.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index b57457c..7e620c7 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -42,16 +42,16 @@ is_fs_type_nfs() is_ssh_dump_target() { - grep -q "^ssh[[:blank:]].*@" /etc/kdump.conf + [[ $(kdump_get_conf_val ssh) == *@* ]] } is_nfs_dump_target() { - if grep -q "^nfs" /etc/kdump.conf; then + if [[ $(kdump_get_conf_val nfs) ]]; then return 0; fi - if is_fs_type_nfs $(get_dracut_args_fstype "$(grep "^dracut_args .*\-\-mount" /etc/kdump.conf)"); then + if is_fs_type_nfs $(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)"); then return 0 fi @@ -68,12 +68,12 @@ is_nfs_dump_target() is_raw_dump_target() { - grep -q "^raw" /etc/kdump.conf + [[ $(kdump_get_conf_val raw) ]] } is_fs_dump_target() { - egrep -q "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf + [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix") ]] } # Read kdump config in well formatted style @@ -109,7 +109,7 @@ is_generic_fence_kdump() { [ -x $FENCE_KDUMP_SEND ] || return 1 - grep -q "^fence_kdump_nodes" /etc/kdump.conf + [[ $(kdump_get_conf_val fence_kdump_nodes) ]] } to_dev_name() { @@ -128,17 +128,17 @@ to_dev_name() { is_user_configured_dump_target() { - grep -E -q "^ext[234]|^xfs|^btrfs|^minix|^raw|^nfs|^ssh" /etc/kdump.conf || is_mount_in_dracut_args; + [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh") ]] || is_mount_in_dracut_args } get_user_configured_dump_disk() { local _target - _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw" /etc/kdump.conf 2>/dev/null |awk '{print $2}') + _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw") [ -n "$_target" ] && echo $_target && return - _target=$(get_dracut_args_target "$(grep "^dracut_args .*\-\-mount" /etc/kdump.conf)") + _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") [ -b "$_target" ] && echo $_target } @@ -149,7 +149,7 @@ get_root_fs_device() get_save_path() { - local _save_path=$(awk '$1 == "path" {print $2}' /etc/kdump.conf) + local _save_path=$(kdump_get_conf_val path) [ -z "$_save_path" ] && _save_path=$DEFAULT_PATH # strip the duplicated "/" @@ -175,7 +175,7 @@ get_block_dump_target() is_dump_to_rootfs() { - grep -E "^(failure_action|default)[[:space:]]dump_to_rootfs" /etc/kdump.conf >/dev/null + [[ $(kdump_get_conf_val "failure_action|default") == dump_to_rootfs ]] } get_failure_action_target() @@ -530,7 +530,7 @@ get_ifcfg_filename() { is_dracut_mod_omitted() { local dracut_args dracut_mod=$1 - set -- $(grep "^dracut_args" /etc/kdump.conf) + set -- $(kdump_get_conf_val dracut_args) while [ $# -gt 0 ]; do case $1 in -o|--omit) @@ -559,7 +559,7 @@ is_wdt_active() { # its correctness). is_mount_in_dracut_args() { - grep -q "^dracut_args .*\-\-mount" /etc/kdump.conf + [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] } # If $1 contains dracut_args "--mount", return From 01613b7211a3de096a889000817ebb9da513f4af Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 3 Aug 2021 22:50:02 +0800 Subject: [PATCH 099/454] kdumpctl: use kdump_get_conf_val to read config values Also fixed kdumpctl, use `awk` instead of `cut` to read core_collector's executable name correctly when its arguments are not seperated by space. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdumpctl | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/kdumpctl b/kdumpctl index db3a301..3f92dac 100755 --- a/kdumpctl +++ b/kdumpctl @@ -339,8 +339,8 @@ check_files_modified() #also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. modified_files=$(get_pcs_cluster_modified_files) - EXTRA_BINS=`grep ^kdump_post $KDUMP_CONFIG_FILE | cut -d\ -f2` - CHECK_FILES=`grep ^kdump_pre $KDUMP_CONFIG_FILE | cut -d\ -f2` + EXTRA_BINS=$(kdump_get_conf_val kdump_post) + CHECK_FILES=$(kdump_get_conf_val kdump_pre) HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" if [ -d /etc/kdump/post.d ]; then for file in /etc/kdump/post.d/*; do @@ -357,17 +357,17 @@ check_files_modified() done fi HOOKS="$HOOKS $POST_FILES $PRE_FILES" - CORE_COLLECTOR=`grep ^core_collector $KDUMP_CONFIG_FILE | cut -d\ -f2` + CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}') CORE_COLLECTOR=`type -P $CORE_COLLECTOR` # POST_FILES and PRE_FILES are already checked against executable, need not to check again. EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" - CHECK_FILES=`grep ^extra_bins $KDUMP_CONFIG_FILE | cut -d\ -f2-` + CHECK_FILES=$(kdump_get_conf_val extra_bins) EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR" [[ -e /etc/fstab ]] && files="$files /etc/fstab" # Check for any updated extra module - EXTRA_MODULES="$(grep ^extra_modules $KDUMP_CONFIG_FILE | sed 's/^extra_modules\s*//')" + EXTRA_MODULES="$(kdump_get_conf_val extra_modules)" if [ -n "$EXTRA_MODULES" ]; then if [ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]; then files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" @@ -555,8 +555,7 @@ check_system_modified() check_rebuild() { local capture_capable_initrd="1" - local _force_rebuild force_rebuild="0" - local _force_no_rebuild force_no_rebuild="0" + local force_rebuild force_no_rebuild local ret system_modified="0" setup_initrd @@ -565,22 +564,18 @@ check_rebuild() return 1 fi - _force_no_rebuild=`grep ^force_no_rebuild $KDUMP_CONFIG_FILE 2>/dev/null` - if [ $? -eq 0 ]; then - force_no_rebuild=`echo $_force_no_rebuild | cut -d' ' -f2` - if [ "$force_no_rebuild" != "0" ] && [ "$force_no_rebuild" != "1" ];then - derror "Error: force_no_rebuild value is invalid" - return 1 - fi + force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) + force_no_rebuild=${force_no_rebuild:-0} + if [ "$force_no_rebuild" != "0" ] && [ "$force_no_rebuild" != "1" ];then + derror "Error: force_no_rebuild value is invalid" + return 1 fi - _force_rebuild=`grep ^force_rebuild $KDUMP_CONFIG_FILE 2>/dev/null` - if [ $? -eq 0 ]; then - force_rebuild=`echo $_force_rebuild | cut -d' ' -f2` - if [ "$force_rebuild" != "0" ] && [ "$force_rebuild" != "1" ];then - derror "Error: force_rebuild value is invalid" - return 1 - fi + force_rebuild=$(kdump_get_conf_val force_rebuild) + force_rebuild=${force_rebuild:-0} + if [ "$force_rebuild" != "0" ] && [ "$force_rebuild" != "1" ];then + derror "Error: force_rebuild value is invalid" + return 1 fi if [[ "$force_no_rebuild" == "1" && "$force_rebuild" == "1" ]]; then @@ -867,7 +862,7 @@ save_raw() local kdump_dir local raw_target - raw_target=$(awk '$1 ~ /^raw$/ { print $2; }' $KDUMP_CONFIG_FILE) + raw_target=$(kdump_get_conf_val raw) [ -z "$raw_target" ] && return 0 [ -b "$raw_target" ] || { derror "raw partition $raw_target not found" @@ -878,7 +873,7 @@ save_raw() dwarn "Warning: Detected '$check_fs' signature on $raw_target, data loss is expected." return 0 fi - kdump_dir=`grep ^path $KDUMP_CONFIG_FILE | cut -d' ' -f2-` + kdump_dir=$(kdump_get_conf_val path) if [ -z "${kdump_dir}" ]; then coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`" else @@ -1018,8 +1013,8 @@ check_failure_action_config() local failure_action local option="failure_action" - default_option=$(awk '$1 ~ /^default$/ {print $2;}' $KDUMP_CONFIG_FILE) - failure_action=$(awk '$1 ~ /^failure_action$/ {print $2;}' $KDUMP_CONFIG_FILE) + default_option=$(kdump_get_conf_val default) + failure_action=$(kdump_get_conf_val failure_action) if [ -z "$failure_action" -a -z "$default_option" ]; then return 0 @@ -1047,7 +1042,7 @@ check_final_action_config() { local final_action - final_action=$(awk '$1 ~ /^final_action$/ {print $2;}' $KDUMP_CONFIG_FILE) + final_action=$(kdump_get_conf_val final_action) if [ -z "$final_action" ]; then return 0 else From dfb76467c9d9462e91e4dd8838f461fb7ab2538f Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 16:22:17 +0800 Subject: [PATCH 100/454] kdumpctl: fix fragile loops over find output For loops over find output are fragile, use a while read loop: https://github.com/koalaman/shellcheck/wiki/SC2044 Signed-off-by: Kairui Song Acked-by: Philipp Rudo /dev/null) + while IFS= read -r -d '' _i; do + _attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null) if [ -z "$_attr" ]; then - restorecon $_i; + restorecon "$_i"; fi - done + done < <(find "$_path" -print0) } check_fence_kdump_config() From 80525afaceac3fa6bdf6e57686f66ab497d2f153 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 15:44:02 +0800 Subject: [PATCH 101/454] kdumpctl: refine grep usage Use `grep -q` instead of redirect to /dev/null. Use `grep -c` instead, as suggested in: https://github.com/koalaman/shellcheck/wiki/SC2126 Use `grep -E` instead of `egrep`. https://github.com/koalaman/shellcheck/wiki/SC2196 Signed-off-by: Kairui Song --- kdumpctl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kdumpctl b/kdumpctl index 01858a3..bb3d42a 100755 --- a/kdumpctl +++ b/kdumpctl @@ -506,7 +506,7 @@ check_fs_modified() # if --mount argument present then match old and new target, mount # point and file system. If any of them mismatches then rebuild - echo $_dracut_args | grep "\-\-mount" &> /dev/null + echo $_dracut_args | grep -q "\-\-mount" if [[ $? -eq 0 ]];then set -- $(echo $_dracut_args | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) _old_dev=$1 @@ -596,7 +596,7 @@ check_rebuild() #in case of fadump mode, check whether the default/target #initrd is already built with dump capture capability if [ "$DEFAULT_DUMP_MODE" == "fadump" ]; then - capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE $TARGET_INITRD | grep -e ^kdumpbase$ -e ^zz-fadumpinit$ | wc -l) + capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$) fi fi @@ -761,7 +761,7 @@ check_and_wait_network_ready() # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa ddebug "$errmsg" - echo $errmsg | grep -q "Permission denied\|No such file or directory\|Host key verification failed" &> /dev/null + echo $errmsg | grep -q "Permission denied\|No such file or directory\|Host key verification failed" if [ $? -eq 0 ]; then derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" return 1 @@ -901,7 +901,7 @@ local_fs_dump_target() { local _target - _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) + _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) if [ $? -eq 0 ]; then echo $_target|awk '{print $2}' fi @@ -964,7 +964,7 @@ check_fence_kdump_config() return 1 fi # node can be ipaddr - echo "$ipaddrs " | grep "$node " > /dev/null + echo "$ipaddrs " | grep -q "$node " if [ $? -eq 0 ]; then derror "Option fence_kdump_nodes cannot contain $node" return 1 From 075e62252ec13e582e8aaa43a0fefee1ad5d8a58 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 01:58:04 +0800 Subject: [PATCH 102/454] mkdumprd: use kdump_get_conf_val to read config values Simplify the code and cover more corner cases. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkdumprd | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/mkdumprd b/mkdumprd index d554511..8687b30 100644 --- a/mkdumprd +++ b/mkdumprd @@ -23,7 +23,6 @@ if [ $? -ne 0 ]; then exit 1 fi -conf_file="/etc/kdump.conf" SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" SAVE_PATH=$(get_save_path) OVERRIDE_RESETTABLE=0 @@ -312,19 +311,6 @@ handle_default_dump_target() check_size fs $_target } -get_override_resettable() -{ - local override_resettable - - override_resettable=$(grep "^override_resettable" $conf_file) - if [ -n "$override_resettable" ]; then - OVERRIDE_RESETTABLE=$(echo $override_resettable | cut -d' ' -f2) - if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then - perror_exit "override_resettable value $OVERRIDE_RESETTABLE is invalid" - fi - fi -} - # $1: function name for_each_block_target() { @@ -363,9 +349,13 @@ is_unresettable() #return true if resettable check_resettable() { - local _ret _target + local _ret _target _override_resettable - get_override_resettable + _override_resettable=$(kdump_get_conf_val override_resettable) + OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE} + if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then + perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid" + fi for_each_block_target is_unresettable _ret=$? @@ -395,7 +385,7 @@ if ! check_crypt; then fi # firstly get right SSH_KEY_LOCATION -keyfile=$(awk '/^sshkey/ {print $2}' $conf_file) +keyfile=$(kdump_get_conf_val sshkey) if [ -f "$keyfile" ]; then # canonicalize the path SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile) From 227fc2bc7dcd9ebc328634dc421373624ba22cc2 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 03:50:04 +0800 Subject: [PATCH 103/454] mkdumprd: make dracut_args an array again To make arguments list work as expected, array is preferred. Use xargs only to parse the "dracut_args" config value, and pass the array directly to dracut. Check following link for details: https://github.com/koalaman/shellcheck/wiki/SC2089 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkdumprd | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mkdumprd b/mkdumprd index 8687b30..c7538a9 100644 --- a/mkdumprd +++ b/mkdumprd @@ -28,7 +28,7 @@ SAVE_PATH=$(get_save_path) OVERRIDE_RESETTABLE=0 extra_modules="" -dracut_args="--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o \"plymouth dash resume ifcfg earlykdump\"" +dracut_args=( --add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump" ) readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." @@ -45,15 +45,15 @@ trap ' trap 'exit 1;' SIGINT add_dracut_arg() { - dracut_args="$dracut_args $@" + dracut_args+=( "$@" ) } add_dracut_mount() { - add_dracut_arg "--mount" "\"$1\"" + add_dracut_arg "--mount" "$1" } add_dracut_sshkey() { - add_dracut_arg "--sshkey" "\"$1\"" + add_dracut_arg "--sshkey" "$1" } # caller should ensure $1 is valid and mounted in 1st kernel @@ -428,7 +428,9 @@ do verify_core_collector "$config_val" ;; dracut_args) - add_dracut_arg $config_val + while read -r dracut_arg; do + add_dracut_arg "$dracut_arg" + done <<< "$(echo "$config_val" | xargs -n 1 echo)" ;; *) ;; @@ -439,7 +441,7 @@ handle_default_dump_target if [ -n "$extra_modules" ] then - add_dracut_arg "--add-drivers" \"$extra_modules\" + add_dracut_arg "--add-drivers" "$extra_modules" fi # TODO: The below check is not needed anymore with the introduction of @@ -455,7 +457,7 @@ if ! is_fadump_capable; then add_dracut_arg "--no-hostonly-default-device" fi -echo "$dracut_args $@" | xargs dracut +dracut "${dracut_args[@]}" "$@" _rc=$? sync From e4c7b5bbf598be896ae6aeb7b842a15b4be63d38 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 03:53:35 +0800 Subject: [PATCH 104/454] mkdumprd: remove some redundant echo Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkdumprd | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mkdumprd b/mkdumprd index c7538a9..de0e22d 100644 --- a/mkdumprd +++ b/mkdumprd @@ -94,7 +94,7 @@ to_mount() { #$1=dump target #called from while loop and shouldn't read from stdin, so we're using "ssh -n" get_ssh_size() { - local _opt _out _size + local _opt _out _opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes" _out=$(ssh -q -n $_opt $1 "df -P $SAVE_PATH") [ $? -ne 0 ] && { @@ -102,8 +102,7 @@ get_ssh_size() { } #ssh output removed the line break, so print field NF-2 - _size=$(echo -n $_out| awk '{avail=NF-2; print $avail}') - echo -n $_size + echo -n "$_out" | awk '{avail=NF-2; print $avail}' } #mkdir if save path does not exist on ssh dump target @@ -134,14 +133,13 @@ mkdir_save_path_ssh() #Function: get_fs_size #$1=dump target get_fs_size() { - local _mnt=$(get_mntpoint_from_target $1) - echo -n $(df -P "${_mnt}/$SAVE_PATH"|tail -1|awk '{print $4}') + df -P "$(get_mntpoint_from_target "$1")/$SAVE_PATH"|tail -1|awk '{print $4}' } #Function: get_raw_size #$1=dump target get_raw_size() { - echo -n $(fdisk -s "$1") + fdisk -s "$1" } #Function: check_size From d6449e7293fb426ebb9f0bffee57d675573a64d6 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 17:15:42 +0800 Subject: [PATCH 105/454] mkdumprd: fix multiple issues with get_ssh_size Currently get_ssh_size is not working as expected, it should return the target's available space, but it will include df's header row string as the result. Fix this issue by only use the last output line. And the _opt variable will be used as args so it should be an array. Also remove the awk call, just use `df --output=avail` instead. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkdumprd | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mkdumprd b/mkdumprd index de0e22d..bc50208 100644 --- a/mkdumprd +++ b/mkdumprd @@ -94,15 +94,14 @@ to_mount() { #$1=dump target #called from while loop and shouldn't read from stdin, so we're using "ssh -n" get_ssh_size() { - local _opt _out - _opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes" - _out=$(ssh -q -n $_opt $1 "df -P $SAVE_PATH") - [ $? -ne 0 ] && { - perror_exit "checking remote ssh server available size failed." - } + local _out + local _opt=("-i" "$SSH_KEY_LOCATION" "-o" "BatchMode=yes" "-o" "StrictHostKeyChecking=yes") - #ssh output removed the line break, so print field NF-2 - echo -n "$_out" | awk '{avail=NF-2; print $avail}' + if ! _out=$(ssh -q -n "${_opt[@]}" "$1" "df" "--output=avail" "$SAVE_PATH"); then + perror_exit "checking remote ssh server available size failed." + fi + + echo -n "$_out" | tail -1 } #mkdir if save path does not exist on ssh dump target From c486b1fa3010c4c5f190ece9a2ed0a1430dfe7b5 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 7 Sep 2021 14:42:30 +0800 Subject: [PATCH 106/454] mkdumprd: remove an awk call in get_fs_size By using `df --output=avail`, the awk call can be dropped. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkdumprd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdumprd b/mkdumprd index bc50208..79cc6b5 100644 --- a/mkdumprd +++ b/mkdumprd @@ -132,7 +132,7 @@ mkdir_save_path_ssh() #Function: get_fs_size #$1=dump target get_fs_size() { - df -P "$(get_mntpoint_from_target "$1")/$SAVE_PATH"|tail -1|awk '{print $4}' + df --output=avail "$(get_mntpoint_from_target "$1")/$SAVE_PATH" | tail -1 } #Function: get_raw_size From 3a4b0351d0f31de739a2aae794e0e2af7fcc4942 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 18 Aug 2021 15:45:20 +0800 Subject: [PATCH 107/454] mkdumprd: use array to store ssh arguments in mkdir_save_path_ssh For storing arguments, plain string is not a good choice. Array is preferred: See: https://github.com/koalaman/shellcheck/wiki/SC2089 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkdumprd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mkdumprd b/mkdumprd index 79cc6b5..aa0f785 100644 --- a/mkdumprd +++ b/mkdumprd @@ -111,20 +111,20 @@ get_ssh_size() { mkdir_save_path_ssh() { local _opt _dir - _opt="-i $SSH_KEY_LOCATION -o BatchMode=yes -o StrictHostKeyChecking=yes" - ssh -qn $_opt $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null + _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) + ssh -qn "${_opt[@]}" $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null _ret=$? if [ $_ret -ne 0 ]; then perror_exit "mkdir failed on $1:$SAVE_PATH" fi #check whether user has write permission on $1:$SAVE_PATH - _dir=$(ssh -qn $_opt $1 mktemp -dqp $SAVE_PATH 2>/dev/null) + _dir=$(ssh -qn "${_opt[@]}" $1 mktemp -dqp $SAVE_PATH 2>/dev/null) _ret=$? if [ $_ret -ne 0 ]; then perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" fi - ssh -qn $_opt $1 rmdir $_dir + ssh -qn "${_opt[@]}" $1 rmdir $_dir return 0 } From 982205d6072b1c10b2f0eff44c3ccbfa92dd3198 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 03:06:57 +0800 Subject: [PATCH 108/454] mkfadumprd: make _dracut_isolate_args an array To make arguments list work as expected, array is preferred. Check following link for details: https://github.com/koalaman/shellcheck/wiki/SC2089 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkfadumprd | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mkfadumprd b/mkfadumprd index aecf2a8..5c87933 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -51,14 +51,17 @@ if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$F fi ### Pack it into the normal boot initramfs with zz-fadumpinit module -_dracut_isolate_args="--rebuild $REBUILD_INITRD --add zz-fadumpinit \ - -i $MKFADUMPRD_TMPDIR/fadumproot /fadumproot \ - -i $MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt - /usr/lib/dracut/fadump-kernel-modules.txt" +_dracut_isolate_args=(\ + --rebuild "$REBUILD_INITRD" --add zz-fadumpinit \ + -i "$MKFADUMPRD_TMPDIR/fadumproot" /fadumproot + -i "$MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt" + /usr/lib/dracut/fadump-kernel-modules.txt +) if is_squash_available; then - _dracut_isolate_args="$_dracut_isolate_args --add squash" + _dracut_isolate_args+=( --add squash ) fi -if ! dracut --force --quiet $_dracut_isolate_args $@ "$TARGET_INITRD"; then + +if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability" fi From 46542ccda5df42a8b07e1d7fee629374e51e732a Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 02:59:43 +0800 Subject: [PATCH 109/454] dracut-module-setup.sh: rework kdump_get_ip_route_field Avoid duplicated echo / cut / grep call, just use sed. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 53abdc7..d7f8cb5 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -523,9 +523,7 @@ kdump_get_ip_route() kdump_get_ip_route_field() { - if `echo $1 | grep -q $2`; then - echo ${1##*$2} | cut -d ' ' -f1 - fi + echo "$1" | sed -n -e "s/^.*\<$2\>\s\+\(\S\+\).*$/\1/p" } kdump_get_remote_ip() From ba7aa447b25f2c66f48ff7ca4a139eb39e4f2340 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 14:29:10 +0800 Subject: [PATCH 110/454] dracut-module-setup.sh: remove an unused variable Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index d7f8cb5..7396403 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -997,8 +997,6 @@ kdump_install_random_seed() { } kdump_install_systemd_conf() { - local failure_action=$(kdump_get_conf_val "failure_action") - # Kdump turns out to require longer default systemd mount timeout # than 1st kernel(90s by default), we use default 300s for kdump. grep -r "^[[:space:]]*DefaultTimeoutStartSec=" ${initdir}/etc/systemd/system.conf* &>/dev/null From 49dd4fcdbb9a21e938829e014d2db7ec3e5d2fea Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 15:41:10 +0800 Subject: [PATCH 111/454] dracut-module-setup.sh: fix _bondoptions wrong references Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 7396403..815abeb 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -391,13 +391,13 @@ kdump_setup_bond() { _bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options") - if [[ -z "_bondoptions" ]]; then + if [[ -z "$_bondoptions" ]]; then dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." source_ifcfg_file $_netdev _bondoptions="$(echo $BONDING_OPTS | xargs echo | tr " " ",")" fi - if [[ -z "_bondoptions" ]]; then + if [[ -z "$_bondoptions" ]]; then derror "Get empty bond options" exit 1 fi From da3ad9cbdaa332ed9384799e4b3198b9e55c5cd3 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 15:47:43 +0800 Subject: [PATCH 112/454] dracut-module-setup.sh: use "*" to expend array as string As suggested by: https://github.com/koalaman/shellcheck/wiki/SC2199 The array is not quoted here but implicitly concatenate still happens, could be harmless but shellcheck complains about it so fix it. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 815abeb..3d465c4 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -94,7 +94,7 @@ kdump_setup_dns() { _tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS") array=(${_tmp//|/ }) - if [[ ${array[@]} ]]; then + if [[ ${array[*]} ]]; then for _dns in "${array[@]}" do echo "nameserver=$_dns" >> "$_dnsfile" From dfe7555323e22d3f23621fcdae11b2c467754175 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 15:51:34 +0800 Subject: [PATCH 113/454] dracut-module-setup.sh: fix a ambiguous variable reference Wrap the variable with {...}, else it may get interpreted as array due to the '[' char next to it. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 3d465c4..8b0398a 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -689,11 +689,11 @@ kdump_install_conf() { case "$_opt" in raw) _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev $_val) - sed -i -e "s#^$_opt[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf + sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf ;; ext[234]|xfs|btrfs|minix) _pdev=$(kdump_get_persistent_dev $_val) - sed -i -e "s#^$_opt[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf + sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf ;; ssh|nfs) kdump_install_net "$_val" From 3b2fa982bbe413e61ac53fa114782e1f08f8a939 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 16:16:44 +0800 Subject: [PATCH 114/454] dracut-module-setup.sh: fix a loop over ls issue Iterating over ls output is fragile: https://github.com/koalaman/shellcheck/wiki/SC2045 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 8b0398a..f13b1a7 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -353,7 +353,9 @@ kdump_setup_ifname() { kdump_setup_bridge() { local _netdev=$1 local _brif _dev _mac _kdumpdev - for _dev in `ls /sys/class/net/$_netdev/brif/`; do + for _dev in "/sys/class/net/$_netdev/brif/"*; do + [[ -e $_dev ]] || continue + _dev=${_dev##*/} _kdumpdev=$_dev if kdump_is_bond "$_dev"; then $(kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") From 67e559a6b905b8f06a0929b7d7c86130fbe30638 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 16:29:55 +0800 Subject: [PATCH 115/454] dracut-module-setup.sh: make iscsi check fail early if cd failed As suggested by: https://github.com/koalaman/shellcheck/wiki/SC2164 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index f13b1a7..267c98e 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -855,7 +855,7 @@ kdump_check_iscsi_targets () { _dev=$1 [[ -L /sys/dev/block/$_dev ]] || return - cd "$(readlink -f /sys/dev/block/$_dev)" + cd "$(readlink -f "/sys/dev/block/$_dev")" || return 1 until [[ -d sys || -d iscsi_session ]]; do cd .. done From 3b0157197b4dcc7c06487d5f44395317c5f4670f Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 15:15:44 +0800 Subject: [PATCH 116/454] dracut-module-setup.sh: remove surrounding $() for subshell Some functions are executed in subshell to avoid variable environment pollution. But the surrounding $() is not needed, and it may lead to executing output which is unexpected here. See: https://github.com/koalaman/shellcheck/wiki/SC2091 Signed-off-by: Kairui Song Suggested-by: Coiby Xu --- dracut-module-setup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 267c98e..af17736 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -358,7 +358,7 @@ kdump_setup_bridge() { _dev=${_dev##*/} _kdumpdev=$_dev if kdump_is_bond "$_dev"; then - $(kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") + (kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") if [[ $? != 0 ]]; then exit 1 fi @@ -441,7 +441,7 @@ kdump_setup_vlan() { derror "Vlan over bridge is not supported!" exit 1 elif kdump_is_bond "$_phydev"; then - $(kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") + (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") if [[ $? != 0 ]]; then exit 1 fi @@ -560,7 +560,7 @@ kdump_install_net() { _znet_netdev=$(find_online_znet_device) if [[ -n "$_znet_netdev" ]]; then _nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev") - $(kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet") + (kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet") if [[ $? != 0 ]]; then derror "Failed to set up znet" exit 1 @@ -591,7 +591,7 @@ kdump_install_net() { if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then - $(kdump_setup_bond "$_netdev" "$_nm_show_cmd") + (kdump_setup_bond "$_netdev" "$_nm_show_cmd") if [[ $? != 0 ]]; then exit 1 fi From 6d45257cc15b3a5b28ed3bfdacb06af065aaecb7 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 15:14:00 +0800 Subject: [PATCH 117/454] bash scripts: remove useless cat Some `cat` calls are useless, remove them to make it cleaner. See: https://github.com/koalaman/shellcheck/wiki/SC2002 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 6 ++++-- kdumpctl | 20 +++++++++++--------- mkdumprd | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index af17736..ef731fc 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -114,7 +114,7 @@ kdump_setup_dns() { _dns=$(echo $_nameserver | cut -d' ' -f2) [ -z "$_dns" ] && continue - if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ]; then + if [ ! -f $_dnsfile ] || ! grep -q "$_dns" "$_dnsfile" ; then echo "nameserver=$_dns" >> "$_dnsfile" fi done < "/etc/resolv.conf" @@ -988,7 +988,9 @@ kdump_configure_fence_kdump () { # Install a random seed used to feed /dev/urandom # By the time kdump service starts, /dev/uramdom is already fed by systemd kdump_install_random_seed() { - local poolsize=`cat /proc/sys/kernel/random/poolsize` + local poolsize + + poolsize=$( Date: Wed, 4 Aug 2021 15:18:59 +0800 Subject: [PATCH 118/454] bash scripts: get rid of expr and let As suggested by: https://github.com/koalaman/shellcheck/wiki/SC2219 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 2 +- kdumpctl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index ef731fc..fc90912 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -196,7 +196,7 @@ cal_netmask_by_prefix() { _res="$_first_part" _tmp=$((_octets_total*_bits_per_octet-_prefix)) - _zero_bits=$(expr $_tmp % $_bits_per_group) + _zero_bits=$((_tmp % _bits_per_group)) if [[ "$_zero_bits" -ne 0 ]]; then _second_part=$((_max_group_value >> _zero_bits << _zero_bits)) if ((_ipv6)); then diff --git a/kdumpctl b/kdumpctl index 2226417..3e92804 100755 --- a/kdumpctl +++ b/kdumpctl @@ -772,7 +772,7 @@ check_and_wait_network_ready() fi cur=$(date +%s) - let "diff = $cur - $start_time" + diff=$((cur - start_time)) # 60s time out if [ $diff -gt 180 ]; then break; @@ -835,7 +835,7 @@ show_reserved_mem() local mem_mb mem=$( Date: Wed, 4 Aug 2021 15:46:27 +0800 Subject: [PATCH 119/454] bash scripts: get rid of unnecessary sed calls Use bash builtin string substitution instead, as suggested by: https://github.com/koalaman/shellcheck/wiki/SC2001 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 8 ++++---- mkdumprd | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index fc90912..f37d2d2 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -288,7 +288,7 @@ kdump_handle_mulitpath_route() { while IFS="" read _route; do if [[ "$_route" =~ [[:space:]]+nexthop ]]; then - _route=$(echo "$_route" | sed -e 's/^[[:space:]]*//') + _route=${_route##[[:space:]]} # Parse multipath route, using previous _target [[ "$_target" == 'default' ]] && continue [[ "$_route" =~ .*via.*\ $_netdev ]] || continue @@ -373,7 +373,7 @@ kdump_setup_bridge() { fi _brif+="$_kdumpdev," done - echo " bridge=$_netdev:$(echo $_brif | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/41bridge.conf + echo " bridge=$_netdev:${_brif%,}" >> "${initdir}/etc/cmdline.d/41bridge.conf" } # drauct takes bond=[::[:]] syntax to parse @@ -389,7 +389,7 @@ kdump_setup_bond() { echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf _slaves+="$_kdumpdev," done - echo -n " bond=$_netdev:$(echo $_slaves | sed 's/,$//')" >> ${initdir}/etc/cmdline.d/42bond.conf + echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf" _bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options") @@ -416,7 +416,7 @@ kdump_setup_team() { echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf _slaves+="$_kdumpdev," done - echo " team=$_netdev:$(echo $_slaves | sed -e 's/,$//')" >> ${initdir}/etc/cmdline.d/44team.conf + echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf" #Buggy version teamdctl outputs to stderr! #Try to use the latest version of teamd. teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf diff --git a/mkdumprd b/mkdumprd index 36e2b90..5341245 100644 --- a/mkdumprd +++ b/mkdumprd @@ -58,7 +58,7 @@ add_dracut_sshkey() { # caller should ensure $1 is valid and mounted in 1st kernel to_mount() { - local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _pdev + local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev _new_mntpoint=$(get_kdump_mntpoint_from_target $_target) _fstype="${_fstype:-$(get_fs_type_from_target $_target)}" @@ -67,9 +67,9 @@ to_mount() { if [[ "$_fstype" == "nfs"* ]]; then _pdev=$_target - _options=$(echo $_options | sed 's/,addr=[^,]*//') - _options=$(echo $_options | sed 's/,proto=[^,]*//') - _options=$(echo $_options | sed 's/,clientaddr=[^,]*//') + _sed_cmd+='s/,addr=[^,]*//;' + _sed_cmd+='s/,proto=[^,]*//;' + _sed_cmd+='s/,clientaddr=[^,]*//;' else # for non-nfs _target converting to use udev persistent name _pdev="$(kdump_get_persistent_dev $_target)" @@ -79,13 +79,15 @@ to_mount() { fi # mount fs target as rw in 2nd kernel - _options=$(echo $_options | sed 's/\(^\|,\)ro\($\|,\)/\1rw\2/g') + _sed_cmd+='s/\(^\|,\)ro\($\|,\)/\1rw\2/g;' # with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd # kernel, filter it out here. - _options=$(echo $_options | sed 's/\(^\|,\)noauto\($\|,\)/\1/g') + _sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;' # drop nofail or nobootwait - _options=$(echo $_options | sed 's/\(^\|,\)nofail\($\|,\)/\1/g') - _options=$(echo $_options | sed 's/\(^\|,\)nobootwait\($\|,\)/\1/g') + _sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;' + _sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;' + + _options=$(echo "$_options" | sed "$_sed_cmd") echo "$_pdev $_new_mntpoint $_fstype $_options" } From a416930706944828ae9bd8daf49be8ca998d3fcc Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 4 Aug 2021 15:50:30 +0800 Subject: [PATCH 120/454] bash scripts: always use "read -r" This helps to strip spaces and avoid mangling backslashes: https://github.com/koalaman/shellcheck/wiki/SC2162 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 14 +++++++------- kdumpctl | 2 +- mkdumprd | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index f37d2d2..202fce5 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -106,7 +106,7 @@ kdump_setup_dns() { [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" fi - while read content; + while read -r content; do _nameserver=$(echo $content | grep ^nameserver) [ -z "$_nameserver" ] && continue @@ -265,7 +265,7 @@ kdump_static_ip() { /sbin/ip $_ipv6_flag route show | grep -v default |\ grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\ - while read _route; do + while read -r _route; do _target=`echo $_route | cut -d ' ' -f1` _nexthop=`echo $_route | cut -d ' ' -f3` if [ "x" != "x"$_ipv6_flag ]; then @@ -286,7 +286,7 @@ kdump_handle_mulitpath_route() { _ipv6_flag="-6" fi - while IFS="" read _route; do + while IFS="" read -r _route; do if [[ "$_route" =~ [[:space:]]+nexthop ]]; then _route=${_route##[[:space:]]} # Parse multipath route, using previous _target @@ -465,7 +465,7 @@ find_online_znet_device() { for d in $NETWORK_DEVICES do [ ! -f "$d/online" ] && continue - read ONLINE < $d/online + read -r ONLINE < $d/online if [ $ONLINE -ne 1 ]; then continue fi @@ -473,7 +473,7 @@ find_online_znet_device() { # device is online) if [ -f $d/if_name ] then - read ifname < $d/if_name + read -r ifname < $d/if_name elif [ -d $d/net ] then ifname=$(ls $d/net/) @@ -685,7 +685,7 @@ kdump_install_conf() { kdump_read_conf > "${initdir}/tmp/$$-kdump.conf" - while read _opt _val; + while read -r _opt _val; do # remove inline comments after the end of a directive. case "$_opt" in @@ -753,7 +753,7 @@ kdump_get_iscsi_initiator() { [ -f "$initiator_conf" ] || return 1 - while read _initiator; do + while read -r _initiator; do [ -z "${_initiator%%#*}" ] && continue # Skip comment lines case $_initiator in diff --git a/kdumpctl b/kdumpctl index 3e92804..72c4966 100755 --- a/kdumpctl +++ b/kdumpctl @@ -704,7 +704,7 @@ load_kdump() check_ssh_config() { - while read config_opt config_val; do + while read -r config_opt config_val; do case "$config_opt" in sshkey) # remove inline comments after the end of a directive. diff --git a/mkdumprd b/mkdumprd index 5341245..6621e30 100644 --- a/mkdumprd +++ b/mkdumprd @@ -390,7 +390,7 @@ if [ -f "$keyfile" ]; then SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile) fi -while read config_opt config_val; +while read -r config_opt config_val; do # remove inline comments after the end of a directive. case "$config_opt" in From 54cc5c44befa308e122d93221c65486164ffb3e5 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 01:48:52 +0800 Subject: [PATCH 121/454] bash scripts: use $(...) notation instead of legacy `...` This is a batch update done with following command: `sed -i -e 's/`\([^`]*\)`/\$(\1)/g' mkfadumprd mkdumprd \ kdumpctl dracut-module-setup.sh dracut-fadump-module-setup.sh \ dracut-early-kdump-module-setup.sh` And manually converted some corner cases. This fixes all related issues detected by shellcheck. Make it easier to do clean up in later commits. Check following link for reasons to switch to the new syntax: https://github.com/koalaman/shellcheck/wiki/SC2006 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 22 +++++++++++----------- kdumpctl | 31 +++++++++++++++---------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 202fce5..29a2f27 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -266,8 +266,8 @@ kdump_static_ip() { /sbin/ip $_ipv6_flag route show | grep -v default |\ grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\ while read -r _route; do - _target=`echo $_route | cut -d ' ' -f1` - _nexthop=`echo $_route | cut -d ' ' -f3` + _target=$(echo $_route | cut -d ' ' -f1) + _nexthop=$(echo $_route | cut -d ' ' -f3) if [ "x" != "x"$_ipv6_flag ]; then _target="[$_target]" _nexthop="[$_nexthop]" @@ -293,9 +293,9 @@ kdump_handle_mulitpath_route() { [[ "$_target" == 'default' ]] && continue [[ "$_route" =~ .*via.*\ $_netdev ]] || continue - _weight=`echo "$_route" | cut -d ' ' -f7` + _weight=$(echo "$_route" | cut -d ' ' -f7) if [[ "$_weight" -gt "$_max_weight" ]]; then - _nexthop=`echo "$_route" | cut -d ' ' -f3` + _nexthop=$(echo "$_route" | cut -d ' ' -f3) _max_weight=$_weight if [ "x" != "x"$_ipv6_flag ]; then _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" @@ -305,7 +305,7 @@ kdump_handle_mulitpath_route() { fi else [[ -n "$_rule" ]] && echo "$_rule" - _target=`echo "$_route" | cut -d ' ' -f1` + _target=$(echo "$_route" | cut -d ' ' -f1) _rule="" _max_weight=0 _weight=0 fi done >> ${initdir}/etc/cmdline.d/45route-static.conf\ @@ -383,7 +383,7 @@ kdump_setup_bond() { local _netdev="$1" local _nm_show_cmd="$2" local _dev _mac _slaves _kdumpdev _bondoptions - for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do + for _dev in $(cat /sys/class/net/$_netdev/bonding/slaves); do _mac=$(kdump_get_perm_addr $_dev) _kdumpdev=$(kdump_setup_ifname $_dev) echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf @@ -410,7 +410,7 @@ kdump_setup_bond() { kdump_setup_team() { local _netdev=$1 local _dev _mac _slaves _kdumpdev - for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do + for _dev in $(teamnl $_netdev ports | awk -F':' '{print $2}'); do _mac=$(kdump_get_perm_addr $_dev) _kdumpdev=$(kdump_setup_ifname $_dev) echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf @@ -532,11 +532,11 @@ kdump_get_remote_ip() { local _remote=$(get_remote_host $1) _remote_temp if is_hostname $_remote; then - _remote_temp=`getent ahosts $_remote | grep -v : | head -n 1` + _remote_temp=$(getent ahosts $_remote | grep -v : | head -n 1) if [ -z "$_remote_temp" ]; then - _remote_temp=`getent ahosts $_remote | head -n 1` + _remote_temp=$(getent ahosts $_remote | head -n 1) fi - _remote=`echo $_remote_temp | cut -d' ' -f1` + _remote=$(echo $_remote_temp | cut -d' ' -f1) fi echo $_remote } @@ -908,7 +908,7 @@ get_pcs_fence_kdump_nodes() { pcs cluster sync > /dev/null 2>&1 && pcs cluster cib-upgrade > /dev/null 2>&1 # get cluster nodes from cluster cib, get interface and ip address - nodelist=`pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -` + nodelist=$(pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -) # nodelist is formed as 'uname="node1" uname="node2" ... uname="nodeX"' # we need to convert each to node1, node2 ... nodeX in each iteration diff --git a/kdumpctl b/kdumpctl index 72c4966..1f76bf2 100755 --- a/kdumpctl +++ b/kdumpctl @@ -76,7 +76,7 @@ determine_dump_mode() save_core() { - coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`" + coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" mkdir -p $coredir ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" @@ -290,15 +290,14 @@ get_pcs_cluster_modified_files() is_generic_fence_kdump && return 1 is_pcs_fence_kdump || return 1 - time_stamp=`pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | \ - xargs -0 date +%s --date` + time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date) if [ -n $time_stamp -a $time_stamp -gt $image_time ]; then modified_files="cluster-cib" fi if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then - time_stamp=`stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE` + time_stamp=$(stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE) if [ "$time_stamp" -gt "$image_time" ]; then modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE" fi @@ -358,7 +357,7 @@ check_files_modified() fi HOOKS="$HOOKS $POST_FILES $PRE_FILES" CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}') - CORE_COLLECTOR=`type -P $CORE_COLLECTOR` + CORE_COLLECTOR=$(type -P $CORE_COLLECTOR) # POST_FILES and PRE_FILES are already checked against executable, need not to check again. EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" CHECK_FILES=$(kdump_get_conf_val extra_bins) @@ -395,13 +394,13 @@ check_files_modified() for file in $files; do if [ -e "$file" ]; then - time_stamp=`stat -c "%Y" $file` + time_stamp=$(stat -c "%Y" $file) if [ "$time_stamp" -gt "$image_time" ]; then modified_files="$modified_files $file" fi if [ -L "$file" ]; then file=$(readlink -m $file) - time_stamp=`stat -c "%Y" $file` + time_stamp=$(stat -c "%Y" $file) if [ "$time_stamp" -gt "$image_time" ]; then modified_files="$modified_files $file" fi @@ -591,7 +590,7 @@ check_rebuild() #check to see if dependent files has been modified #since last build of the image file if [ -f $TARGET_INITRD ]; then - image_time=`stat -c "%Y" $TARGET_INITRD 2>/dev/null` + image_time=$(stat -c "%Y" $TARGET_INITRD 2>/dev/null) #in case of fadump mode, check whether the default/target #initrd is already built with dump capture capability @@ -727,7 +726,7 @@ check_ssh_config() done <<< "$(kdump_read_conf)" #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') if [ -z "$SSH_TARGET" ]; then return 1 fi @@ -814,8 +813,8 @@ propagate_ssh_key() fi #now find the target ssh user and server to contact. - SSH_USER=`echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1` - SSH_SERVER=`echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/'` + SSH_USER=$(echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1) + SSH_SERVER=$(echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/') #now send the found key to the found server ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER @@ -844,7 +843,7 @@ check_current_fadump_status() { # Check if firmware-assisted dump has been registered. rc=$(<$FADUMP_REGISTER_SYS_NODE) - [[ $rc -eq 1 ]] && return 0 + [ $rc -eq 1 ] && return 0 return 1 } @@ -877,9 +876,9 @@ save_raw() fi kdump_dir=$(kdump_get_conf_val path) if [ -z "${kdump_dir}" ]; then - coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`" + coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" else - coredir="${kdump_dir}/`date +"%Y-%m-%d-%H:%M"`" + coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")" fi mkdir -p "$coredir" @@ -956,8 +955,8 @@ selinux_relabel() check_fence_kdump_config() { - local hostname=`hostname` - local ipaddrs=`hostname -I` + local hostname=$(hostname) + local ipaddrs=$(hostname -I) local nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in $nodes; do From 70978c00e5a573f0901ac404067eaea2c6536370 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 17:20:51 +0800 Subject: [PATCH 122/454] bash scripts: replace '[ ]' with '[[ ]]' for bash scripts kdumpctl, mkdumprd, *-module-setup.sh only target bash, since they only run in first kernel and depend on dracut, and dracut depends on bash. So use '[[ ]]' to replace '[ ]'. This is a batch update done with following command: `sed -i -e 's/\(\s\)\[\s\([^]]*\)\s\]/\1\[\[\ \2 \]\]/g' kdumpctl, mkdumprd, *-module-setup.sh` and replaced [ ... -a ... ] with [[ ... ]] && [[ ... ]] manually. See https://tldp.org/LDP/abs/html/testconstructs.html for more details on '[[ ]]', it's more versatile, safer, and slightly faster than '[ ]'. This will also help shfmt to clean up the code in later commits. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-early-kdump-module-setup.sh | 10 +- dracut-module-setup.sh | 108 +++++++------- kdumpctl | 218 ++++++++++++++--------------- mkdumprd | 50 +++---- mkfadumprd | 2 +- 5 files changed, 194 insertions(+), 194 deletions(-) diff --git a/dracut-early-kdump-module-setup.sh b/dracut-early-kdump-module-setup.sh index b25d6b5..00546e0 100755 --- a/dracut-early-kdump-module-setup.sh +++ b/dracut-early-kdump-module-setup.sh @@ -6,8 +6,8 @@ KDUMP_KERNEL="" KDUMP_INITRD="" check() { - if [ ! -f /etc/sysconfig/kdump ] || [ ! -f /lib/kdump/kdump-lib.sh ]\ - || [ -n "${IN_KDUMP}" ] + if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]]\ + || [[ -n "${IN_KDUMP}" ]] then return 1 fi @@ -25,7 +25,7 @@ prepare_kernel_initrd() { prepare_kdump_bootinfo # $kernel is a variable from dracut - if [ "$KDUMP_KERNELVER" != $kernel ]; then + if [[ "$KDUMP_KERNELVER" != $kernel ]]; then dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \ "but the initramfs is generated for kernel version '$kernel'" fi @@ -33,12 +33,12 @@ prepare_kernel_initrd() { install() { prepare_kernel_initrd - if [ ! -f "$KDUMP_KERNEL" ]; then + if [[ ! -f "$KDUMP_KERNEL" ]]; then derror "Could not find required kernel for earlykdump," \ "earlykdump will not work!" return 1 fi - if [ ! -f "$KDUMP_INITRD" ]; then + if [[ ! -f "$KDUMP_INITRD" ]]; then derror "Could not find required kdump initramfs for earlykdump," \ "please ensure kdump initramfs is generated first," \ "earlykdump will not work!" diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 29a2f27..515cff0 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -11,7 +11,7 @@ kdump_module_init() { check() { [[ $debug ]] && set -x #kdumpctl sets this explicitly - if [ -z "$IN_KDUMP" ] || [ ! -f /etc/kdump.conf ] + if [[ -z "$IN_KDUMP" ]] || [[ ! -f /etc/kdump.conf ]] then return 1 fi @@ -41,11 +41,11 @@ depends() { _dep="$_dep ssh-client" fi - if [ "$(uname -m)" = "s390x" ]; then + if [[ "$(uname -m)" = "s390x" ]]; then _dep="$_dep znet" fi - if [ -n "$( ls -A /sys/class/drm 2>/dev/null )" ] || [ -d /sys/module/hyperv_fb ]; then + if [[ -n "$( ls -A /sys/class/drm 2>/dev/null )" ]] || [[ -d /sys/module/hyperv_fb ]]; then add_opt_module drm fi @@ -57,19 +57,19 @@ depends() { } kdump_is_bridge() { - [ -d /sys/class/net/"$1"/bridge ] + [[ -d /sys/class/net/"$1"/bridge ]] } kdump_is_bond() { - [ -d /sys/class/net/"$1"/bonding ] + [[ -d /sys/class/net/"$1"/bonding ]] } kdump_is_team() { - [ -f /usr/bin/teamnl ] && teamnl $1 ports &> /dev/null + [[ -f /usr/bin/teamnl ]] && teamnl $1 ports &> /dev/null } kdump_is_vlan() { - [ -f /proc/net/vlan/"$1" ] + [[ -f /proc/net/vlan/"$1" ]] } # $1: netdev name @@ -78,7 +78,7 @@ source_ifcfg_file() { dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." ifcfg_file=$(get_ifcfg_filename $1) - if [ -f "${ifcfg_file}" ]; then + if [[ -f "${ifcfg_file}" ]]; then . ${ifcfg_file} else dwarning "The ifcfg file of $1 is not found!" @@ -102,19 +102,19 @@ kdump_setup_dns() { else dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script" source_ifcfg_file "$_netdev" - [ -n "$DNS1" ] && echo "nameserver=$DNS1" > "$_dnsfile" - [ -n "$DNS2" ] && echo "nameserver=$DNS2" >> "$_dnsfile" + [[ -n "$DNS1" ]] && echo "nameserver=$DNS1" > "$_dnsfile" + [[ -n "$DNS2" ]] && echo "nameserver=$DNS2" >> "$_dnsfile" fi while read -r content; do _nameserver=$(echo $content | grep ^nameserver) - [ -z "$_nameserver" ] && continue + [[ -z "$_nameserver" ]] && continue _dns=$(echo $_nameserver | cut -d' ' -f2) - [ -z "$_dns" ] && continue + [[ -z "$_dns" ]] && continue - if [ ! -f $_dnsfile ] || ! grep -q "$_dns" "$_dnsfile" ; then + if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then echo "nameserver=$_dns" >> "$_dnsfile" fi done < "/etc/resolv.conf" @@ -243,11 +243,11 @@ kdump_static_ip() { _ipv6_flag="-6" fi - if [ -n "$_ipaddr" ]; then + if [[ -n "$_ipaddr" ]]; then _gateway=$(ip $_ipv6_flag route list dev $_netdev | \ awk '/^default /{print $3}' | head -n 1) - if [ "x" != "x"$_ipv6_flag ]; then + if [[ "x" != "x"$_ipv6_flag ]]; then # _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/" _netmask=${_ipaddr#*\/} _srcaddr="[$_srcaddr]" @@ -268,7 +268,7 @@ kdump_static_ip() { while read -r _route; do _target=$(echo $_route | cut -d ' ' -f1) _nexthop=$(echo $_route | cut -d ' ' -f3) - if [ "x" != "x"$_ipv6_flag ]; then + if [[ "x" != "x"$_ipv6_flag ]]; then _target="[$_target]" _nexthop="[$_nexthop]" fi @@ -297,7 +297,7 @@ kdump_handle_mulitpath_route() { if [[ "$_weight" -gt "$_max_weight" ]]; then _nexthop=$(echo "$_route" | cut -d ' ' -f3) _max_weight=$_weight - if [ "x" != "x"$_ipv6_flag ]; then + if [[ "x" != "x"$_ipv6_flag ]]; then _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" else _rule="rd.route=$_target:$_nexthop:$kdumpnic" @@ -322,7 +322,7 @@ kdump_get_mac_addr() { #of its slaves, we should use perm address kdump_get_perm_addr() { local addr=$(ethtool -P $1 | sed -e 's/Permanent address: //') - if [ -z "$addr" ] || [ "$addr" = "00:00:00:00:00:00" ] + if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]] then derror "Can't get the permanent address of $1" else @@ -420,7 +420,7 @@ kdump_setup_team() { #Buggy version teamdctl outputs to stderr! #Try to use the latest version of teamd. teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf - if [ $? -ne 0 ] + if [[ $? -ne 0 ]] then derror "teamdctl failed." exit 1 @@ -460,25 +460,25 @@ find_online_znet_device() { local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" local NETWORK_DEVICES d ifname ONLINE - [ ! -d "$CCWGROUPBUS_DEVICEDIR" ] && return + [[ ! -d "$CCWGROUPBUS_DEVICEDIR" ]] && return NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) for d in $NETWORK_DEVICES do - [ ! -f "$d/online" ] && continue + [[ ! -f "$d/online" ]] && continue read -r ONLINE < $d/online - if [ $ONLINE -ne 1 ]; then + if [[ $ONLINE -ne 1 ]]; then continue fi # determine interface name, if there (only for qeth and if # device is online) - if [ -f $d/if_name ] + if [[ -f $d/if_name ]] then read -r ifname < $d/if_name - elif [ -d $d/net ] + elif [[ -d $d/net ]] then ifname=$(ls $d/net/) fi - [ -n "$ifname" ] && break + [[ -n "$ifname" ]] && break done echo -n "$ifname" } @@ -533,7 +533,7 @@ kdump_get_remote_ip() local _remote=$(get_remote_host $1) _remote_temp if is_hostname $_remote; then _remote_temp=$(getent ahosts $_remote | grep -v : | head -n 1) - if [ -z "$_remote_temp" ]; then + if [[ -z "$_remote_temp" ]]; then _remote_temp=$(getent ahosts $_remote | head -n 1) fi _remote=$(echo $_remote_temp | cut -d' ' -f1) @@ -568,7 +568,7 @@ kdump_install_net() { fi _static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) - if [ -n "$_static" ]; then + if [[ -n "$_static" ]]; then _proto=none elif is_ipv6_address $_srcaddr; then _proto=auto6 @@ -583,7 +583,7 @@ kdump_install_net() { # so we have to avoid adding duplicates # We should also check /proc/cmdline for existing ip=xx arg. # For example, iscsi boot will specify ip=xxx arg in cmdline. - if [ ! -f $_ip_conf ] || ! grep -q $_ip_opts $_ip_conf &&\ + if [[ ! -f $_ip_conf ]] || ! grep -q $_ip_opts $_ip_conf &&\ ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then echo "$_ip_opts" >> $_ip_conf fi @@ -606,7 +606,7 @@ kdump_install_net() { kdump_setup_dns "$_netdev" "$_nm_show_cmd" - if [ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]; then + if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then # network-manager module needs this parameter echo "rd.neednet" >> ${initdir}/etc/cmdline.d/50neednet.conf fi @@ -618,8 +618,8 @@ kdump_install_net() { # the default gate way for network dump, eth1 in the fence kdump path will # call kdump_install_net again and we don't want eth1 to be the default # gateway. - if [ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ] && - [ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]; then + if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] && + [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf fi @@ -627,21 +627,21 @@ kdump_install_net() { # install etc/kdump/pre.d and /etc/kdump/post.d kdump_install_pre_post_conf() { - if [ -d /etc/kdump/pre.d ]; then + if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then dracut_install $file - elif [ $file != "/etc/kdump/pre.d/*" ]; then + elif [[ $file != "/etc/kdump/pre.d/*" ]]; then echo "$file is not executable" fi done fi - if [ -d /etc/kdump/post.d ]; then + if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then dracut_install $file - elif [ $file != "/etc/kdump/post.d/*" ]; then + elif [[ $file != "/etc/kdump/post.d/*" ]]; then echo "$file is not executable" fi done @@ -670,7 +670,7 @@ default_dump_target_install_conf() echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf # don't touch the path under root mount - if [ "$_mntpoint" != "/" ]; then + if [[ "$_mntpoint" != "/" ]]; then _save_path=${_save_path##"$_mntpoint"} fi @@ -751,10 +751,10 @@ kdump_get_iscsi_initiator() { local _initiator local initiator_conf="/etc/iscsi/initiatorname.iscsi" - [ -f "$initiator_conf" ] || return 1 + [[ -f "$initiator_conf" ]] || return 1 while read -r _initiator; do - [ -z "${_initiator%%#*}" ] && continue # Skip comment lines + [[ -z "${_initiator%%#*}" ]] && continue # Skip comment lines case $_initiator in InitiatorName=*) @@ -770,7 +770,7 @@ kdump_get_iscsi_initiator() { # Figure out iBFT session according to session type is_ibft() { - [ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ] + [[ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ]] } kdump_setup_iscsi_device() { @@ -803,18 +803,18 @@ kdump_setup_iscsi_device() { # get and set username and password details username=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username") - [ "$username" == "" ] && username="" + [[ "$username" == "" ]] && username="" password=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password") - [ "$password" == "" ] && password="" + [[ "$password" == "" ]] && password="" username_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username_in") - [ -n "$username" ] && userpwd_str="$username:$password" + [[ -n "$username" ]] && userpwd_str="$username:$password" # get and set incoming username and password details - [ "$username_in" == "" ] && username_in="" + [[ "$username_in" == "" ]] && username_in="" password_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password_in") - [ "$password_in" == "" ] && password_in="" + [[ "$password_in" == "" ]] && password_in="" - [ -n "$username_in" ] && userpwd_in_str=":$username_in:$password_in" + [[ -n "$username_in" ]] && userpwd_in_str=":$username_in:$password_in" kdump_install_net "$tgt_ipaddr" @@ -837,7 +837,7 @@ kdump_setup_iscsi_device() { # Setup initator initiator_str=$(kdump_get_iscsi_initiator) - [ $? -ne "0" ] && derror "Failed to get initiator name" && return 1 + [[ $? -ne "0" ]] && derror "Failed to get initiator name" && return 1 # If initiator details do not exist already, append. if ! grep -q "$initiator_str" $netroot_conf; then @@ -878,7 +878,7 @@ get_alias() { do # in /etc/hosts, alias can come at the 2nd column entries=$(grep $ip /etc/hosts | awk '{ $1=""; print $0 }') - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then alias_set="$alias_set $entries" fi done @@ -895,7 +895,7 @@ is_localhost() { hostnames="$hostnames $shortnames $aliasname" for name in ${hostnames}; do - if [ "$name" == "$nodename" ]; then + if [[ "$name" == "$nodename" ]]; then return 0 fi done @@ -928,7 +928,7 @@ get_pcs_fence_kdump_nodes() { # retrieves fence_kdump args from config file get_pcs_fence_kdump_args() { - if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then + if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then . $FENCE_KDUMP_CONFIG_FILE echo $FENCE_KDUMP_OPTS fi @@ -966,7 +966,7 @@ kdump_configure_fence_kdump () { echo "fence_kdump_nodes $nodes" >> ${kdump_cfg_file} args=$(get_pcs_fence_kdump_args) - if [ -n "$args" ]; then + if [[ -n "$args" ]]; then echo "fence_kdump_args $args" >> ${kdump_cfg_file} fi @@ -992,7 +992,7 @@ kdump_install_random_seed() { poolsize=$( ${initdir}/etc/systemd/system.conf.d/kdump.conf echo "DefaultTimeoutStartSec=300s" >> ${initdir}/etc/systemd/system.conf.d/kdump.conf diff --git a/kdumpctl b/kdumpctl index 1f76bf2..11782df 100755 --- a/kdumpctl +++ b/kdumpctl @@ -27,7 +27,7 @@ standard_kexec_args="-d -p" # Some default values in case /etc/sysconfig/kdump doesn't include KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug" -if [ -f /etc/sysconfig/kdump ]; then +if [[ -f /etc/sysconfig/kdump ]]; then . /etc/sysconfig/kdump fi @@ -38,7 +38,7 @@ fi #initiate the kdump logger dlog_init -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then echo "failed to initiate the kdump logger." exit 1 fi @@ -48,7 +48,7 @@ single_instance_lock() local rc timeout=5 exec 9>/var/lock/kdump - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Create file lock failed" exit 1 fi @@ -56,7 +56,7 @@ single_instance_lock() flock -n 9 rc=$? - while [ $rc -ne 0 ]; do + while [[ $rc -ne 0 ]]; do dinfo "Another app is currently holding the kdump lock; waiting for it to exit..." flock -w $timeout 9 rc=$? @@ -81,7 +81,7 @@ save_core() mkdir -p $coredir ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then mv $coredir/vmcore-incomplete $coredir/vmcore dinfo "saved a vmcore to $coredir" else @@ -91,12 +91,12 @@ save_core() # pass the dmesg to Abrt tool if exists, in order # to collect the kernel oops message. # https://fedorahosted.org/abrt/ - if [ -x /usr/bin/dumpoops ]; then + if [[ -x /usr/bin/dumpoops ]]; then ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg >/dev/null 2>&1 ddebug "dumpoops -d $coredir/dmesg" dumpoops -d $coredir/dmesg >/dev/null 2>&1 - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then dinfo "kernel oops has been collected by abrt tool" fi fi @@ -122,7 +122,7 @@ rebuild_kdump_initrd() { ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER" $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "mkdumprd: failed to make kdump initrd" return 1 fi @@ -141,7 +141,7 @@ rebuild_initrd() return 1 fi - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then rebuild_fadump_initrd else rebuild_kdump_initrd @@ -154,7 +154,7 @@ rebuild_initrd() check_exist() { for file in $1; do - if [ ! -e "$file" ]; then + if [[ ! -e "$file" ]]; then derror "Error: $file not found." return 1 fi @@ -165,7 +165,7 @@ check_exist() check_executable() { for file in $1; do - if [ ! -x "$file" ]; then + if [[ ! -x "$file" ]]; then derror "Error: $file is not executable." return 1 fi @@ -176,16 +176,16 @@ backup_default_initrd() { ddebug "backup default initrd: $DEFAULT_INITRD" - if [ ! -f "$DEFAULT_INITRD" ]; then + if [[ ! -f "$DEFAULT_INITRD" ]]; then return fi - if [ ! -e $DEFAULT_INITRD_BAK ]; then + if [[ ! -e $DEFAULT_INITRD_BAK ]]; then dinfo "Backing up $DEFAULT_INITRD before rebuild." # save checksum to verify before restoring sha1sum $DEFAULT_INITRD > $INITRD_CHECKSUM_LOCATION cp $DEFAULT_INITRD $DEFAULT_INITRD_BAK - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then dwarn "WARNING: failed to backup $DEFAULT_INITRD." rm -f $DEFAULT_INITRD_BAK fi @@ -196,17 +196,17 @@ restore_default_initrd() { ddebug "restore default initrd: $DEFAULT_INITRD" - if [ ! -f "$DEFAULT_INITRD" ]; then + if [[ ! -f "$DEFAULT_INITRD" ]]; then return fi # If a backup initrd exists, we must be switching back from # fadump to kdump. Restore the original default initrd. - if [ -f $DEFAULT_INITRD_BAK ] && [ -f $INITRD_CHECKSUM_LOCATION ]; then + if [[ -f $DEFAULT_INITRD_BAK ]] && [[ -f $INITRD_CHECKSUM_LOCATION ]]; then # verify checksum before restoring backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }') default_checksum=$(awk '{ print $1 }' "$INITRD_CHECKSUM_LOCATION") - if [ "$default_checksum" != "$backup_checksum" ]; then + if [[ "$default_checksum" != "$backup_checksum" ]]; then dwarn "WARNING: checksum mismatch! Can't restore original initrd.." else rm -f $INITRD_CHECKSUM_LOCATION @@ -226,7 +226,7 @@ check_config() case "$config_opt" in dracut_args) if [[ $config_val == *--mount* ]]; then - if [ $(echo $config_val | grep -o "\-\-mount" | wc -l) -ne 1 ]; then + if [[ $(echo $config_val | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then derror "Multiple mount targets specified in one \"dracut_args\"." return 1 fi @@ -234,7 +234,7 @@ check_config() fi ;; raw) - if [ -d "/proc/device-tree/ibm,opal/dump" ]; then + if [[ -d "/proc/device-tree/ibm,opal/dump" ]]; then dwarn "WARNING: Won't capture opalcore when 'raw' dump target is used." fi config_opt=_target @@ -262,8 +262,8 @@ check_config() return 1 fi - if [ -n "${_opt_rec[$config_opt]}" ]; then - if [ $config_opt == _target ]; then + if [[ -n "${_opt_rec[$config_opt]}" ]]; then + if [[ $config_opt == _target ]]; then derror "More than one dump targets specified" else derror "Duplicated kdump config value of option $config_opt" @@ -292,13 +292,13 @@ get_pcs_cluster_modified_files() time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date) - if [ -n $time_stamp -a $time_stamp -gt $image_time ]; then + if [[ -n $time_stamp ]] && [[ $time_stamp -gt $image_time ]]; then modified_files="cluster-cib" fi - if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then + if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then time_stamp=$(stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE) - if [ "$time_stamp" -gt "$image_time" ]; then + if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE" fi fi @@ -309,13 +309,13 @@ get_pcs_cluster_modified_files() setup_initrd() { prepare_kdump_bootinfo - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "failed to prepare for kdump bootinfo." return 1 fi DEFAULT_INITRD_BAK="$KDUMP_BOOTDIR/.$(basename $DEFAULT_INITRD).default" - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then TARGET_INITRD="$DEFAULT_INITRD" # backup initrd for reference before replacing it @@ -341,16 +341,16 @@ check_files_modified() EXTRA_BINS=$(kdump_get_conf_val kdump_post) CHECK_FILES=$(kdump_get_conf_val kdump_pre) HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" - if [ -d /etc/kdump/post.d ]; then + if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then POST_FILES="$POST_FILES $file" fi done fi - if [ -d /etc/kdump/pre.d ]; then + if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do - if [ -x "$file" ]; then + if [[ -x "$file" ]]; then PRE_FILES="$PRE_FILES $file" fi done @@ -367,8 +367,8 @@ check_files_modified() # Check for any updated extra module EXTRA_MODULES="$(kdump_get_conf_val extra_modules)" - if [ -n "$EXTRA_MODULES" ]; then - if [ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]; then + if [[ -n "$EXTRA_MODULES" ]]; then + if [[ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]]; then files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" fi for _module in $EXTRA_MODULES; do @@ -390,18 +390,18 @@ check_files_modified() # HOOKS is mandatory and need to check the modification time files="$files $HOOKS" check_exist "$files" && check_executable "$EXTRA_BINS" - [ $? -ne 0 ] && return 2 + [[ $? -ne 0 ]] && return 2 for file in $files; do - if [ -e "$file" ]; then + if [[ -e "$file" ]]; then time_stamp=$(stat -c "%Y" $file) - if [ "$time_stamp" -gt "$image_time" ]; then + if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $file" fi - if [ -L "$file" ]; then + if [[ -L "$file" ]]; then file=$(readlink -m $file) time_stamp=$(stat -c "%Y" $file) - if [ "$time_stamp" -gt "$image_time" ]; then + if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $file" fi fi @@ -410,7 +410,7 @@ check_files_modified() fi done - if [ -n "$modified_files" ]; then + if [[ -n "$modified_files" ]]; then dinfo "Detected change(s) in the following file(s): $modified_files" return 1 fi @@ -441,7 +441,7 @@ check_drivers_modified() # Include watchdog drivers if watchdog module is not omitted is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)" - [ -z "$_new_drivers" ] && return 0 + [[ -z "$_new_drivers" ]] && return 0 if is_fadump_capable; then _old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')" @@ -455,7 +455,7 @@ check_drivers_modified() # Skip deprecated/invalid driver name or built-in module _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name $_driver 2>/dev/null) _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n $_driver 2>/dev/null) - if [ $? -ne 0 ] || [ -z "$_module_name" ] || [[ "$_module_filename" = *"(builtin)"* ]]; then + if [[ $? -ne 0 ]] || [[ -z "$_module_name" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then continue fi if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then @@ -491,7 +491,7 @@ check_fs_modified() ddebug "_target=$_target _new_fstype=$_new_fstype" _new_dev=$(kdump_get_persistent_dev $_target) - if [ -z "$_new_dev" ]; then + if [[ -z "$_new_dev" ]]; then perror "Get persistent device name failed" return 2 fi @@ -532,19 +532,19 @@ check_system_modified() check_files_modified ret=$? - if [ $ret -ne 0 ]; then + if [[ $ret -ne 0 ]]; then return $ret fi check_fs_modified ret=$? - if [ $ret -ne 0 ]; then + if [[ $ret -ne 0 ]]; then return $ret fi check_drivers_modified ret=$? - if [ $ret -ne 0 ]; then + if [[ $ret -ne 0 ]]; then return $ret fi @@ -559,20 +559,20 @@ check_rebuild() setup_initrd - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) force_no_rebuild=${force_no_rebuild:-0} - if [ "$force_no_rebuild" != "0" ] && [ "$force_no_rebuild" != "1" ];then + if [[ "$force_no_rebuild" != "0" ]] && [[ "$force_no_rebuild" != "1" ]];then derror "Error: force_no_rebuild value is invalid" return 1 fi force_rebuild=$(kdump_get_conf_val force_rebuild) force_rebuild=${force_rebuild:-0} - if [ "$force_rebuild" != "0" ] && [ "$force_rebuild" != "1" ];then + if [[ "$force_rebuild" != "0" ]] && [[ "$force_rebuild" != "1" ]];then derror "Error: force_rebuild value is invalid" return 1 fi @@ -583,37 +583,37 @@ check_rebuild() fi # Will not rebuild kdump initrd - if [ "$force_no_rebuild" == "1" ]; then + if [[ "$force_no_rebuild" == "1" ]]; then return 0 fi #check to see if dependent files has been modified #since last build of the image file - if [ -f $TARGET_INITRD ]; then + if [[ -f $TARGET_INITRD ]]; then image_time=$(stat -c "%Y" $TARGET_INITRD 2>/dev/null) #in case of fadump mode, check whether the default/target #initrd is already built with dump capture capability - if [ "$DEFAULT_DUMP_MODE" == "fadump" ]; then + if [[ "$DEFAULT_DUMP_MODE" == "fadump" ]]; then capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$) fi fi check_system_modified ret=$? - if [ $ret -eq 2 ]; then + if [[ $ret -eq 2 ]]; then return 1 - elif [ $ret -eq 1 ];then + elif [[ $ret -eq 1 ]];then system_modified="1" fi - if [ $image_time -eq 0 ]; then + if [[ $image_time -eq 0 ]]; then dinfo "No kdump initial ramdisk found." - elif [ "$capture_capable_initrd" == "0" ]; then + elif [[ "$capture_capable_initrd" == "0" ]]; then dinfo "Rebuild $TARGET_INITRD with dump capture support" - elif [ "$force_rebuild" != "0" ]; then + elif [[ "$force_rebuild" != "0" ]]; then dinfo "Force rebuild $TARGET_INITRD" - elif [ "$system_modified" != "0" ]; then + elif [[ "$system_modified" != "0" ]]; then : else return 0 @@ -633,7 +633,7 @@ function load_kdump_kernel_key() # this is only required if DT /ibm,secure-boot is a file. # if it is a dir, we are on OpenPower and don't need this. - if ! [ -f /proc/device-tree/ibm,secure-boot ]; then + if ! [[ -f /proc/device-tree/ibm,secure-boot ]]; then return fi @@ -645,7 +645,7 @@ function load_kdump_kernel_key() # to be idempotent and so as to reduce the potential for confusion. function remove_kdump_kernel_key() { - if [ -z "$KDUMP_KEY_ID" ]; then + if [[ -z "$KDUMP_KEY_ID" ]]; then return fi @@ -692,7 +692,7 @@ load_kdump() remove_kdump_kernel_key - if [ $ret == 0 ]; then + if [[ $ret == 0 ]]; then dinfo "kexec: loaded kdump kernel" return 0 else @@ -707,7 +707,7 @@ check_ssh_config() case "$config_opt" in sshkey) # remove inline comments after the end of a directive. - if [ -f "$config_val" ]; then + if [[ -f "$config_val" ]]; then # canonicalize the path SSH_KEY_LOCATION=$(/usr/bin/readlink -m $config_val) else @@ -727,7 +727,7 @@ check_ssh_config() #make sure they've configured kdump.conf for ssh dumps local SSH_TARGET=$(echo -n $DUMP_TARGET | sed -n '/.*@/p') - if [ -z "$SSH_TARGET" ]; then + if [[ -z "$SSH_TARGET" ]]; then return 1 fi return 0 @@ -750,9 +750,9 @@ check_and_wait_network_ready() retval=$? # ssh exits with the exit status of the remote command or with 255 if an error occurred - if [ $retval -eq 0 ]; then + if [[ $retval -eq 0 ]]; then return 0 - elif [ $retval -ne 255 ]; then + elif [[ $retval -ne 255 ]]; then derror "Could not create $DUMP_TARGET:$SAVE_PATH, you should check the privilege on server side" return 1 fi @@ -760,12 +760,12 @@ check_and_wait_network_ready() # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa ddebug "$errmsg" echo $errmsg | grep -q "Permission denied\|No such file or directory\|Host key verification failed" - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" return 1 fi - if [ $warn_once -eq 1 ]; then + if [[ $warn_once -eq 1 ]]; then dwarn "Network dump target is not usable, waiting for it to be ready..." warn_once=0 fi @@ -773,7 +773,7 @@ check_and_wait_network_ready() cur=$(date +%s) diff=$((cur - start_time)) # 60s time out - if [ $diff -gt 180 ]; then + if [[ $diff -gt 180 ]]; then break; fi sleep 1 @@ -786,7 +786,7 @@ check_and_wait_network_ready() check_ssh_target() { check_and_wait_network_ready - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi return 0 @@ -795,7 +795,7 @@ check_ssh_target() propagate_ssh_key() { check_ssh_config - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate" exit 1 fi @@ -804,7 +804,7 @@ propagate_ssh_key() local errmsg="Failed to propagate ssh key" #Check to see if we already created key, if not, create it. - if [ -f $KEYFILE ]; then + if [[ -f $KEYFILE ]]; then dinfo "Using existing keys..." else dinfo "Generating new ssh keys... " @@ -819,7 +819,7 @@ propagate_ssh_key() #now send the found key to the found server ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER RET=$? - if [ $RET == 0 ]; then + if [[ $RET == 0 ]]; then dinfo "$KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER" return 0 else @@ -843,13 +843,13 @@ check_current_fadump_status() { # Check if firmware-assisted dump has been registered. rc=$(<$FADUMP_REGISTER_SYS_NODE) - [ $rc -eq 1 ] && return 0 + [[ $rc -eq 1 ]] && return 0 return 1 } check_current_status() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then check_current_fadump_status else check_current_kdump_status @@ -864,8 +864,8 @@ save_raw() local raw_target raw_target=$(kdump_get_conf_val raw) - [ -z "$raw_target" ] && return 0 - [ -b "$raw_target" ] || { + [[ -z "$raw_target" ]] && return 0 + [[ -b "$raw_target" ]] || { derror "raw partition $raw_target not found" return 1 } @@ -875,14 +875,14 @@ save_raw() return 0 fi kdump_dir=$(kdump_get_conf_val path) - if [ -z "${kdump_dir}" ]; then + if [[ -z "${kdump_dir}" ]]; then coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" else coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")" fi mkdir -p "$coredir" - [ -d "$coredir" ] || { + [[ -d "$coredir" ]] || { derror "failed to create $coredir" return 1 } @@ -903,7 +903,7 @@ local_fs_dump_target() local _target _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then echo $_target|awk '{print $2}' fi } @@ -931,7 +931,7 @@ path_to_be_relabeled() _path=$(get_save_path) # if $_path is masked by other mount, we will not relabel it. _rmnt=$(df $_mnt/$_path 2>/dev/null | tail -1 | awk '{ print $NF }') - if [ "$_rmnt" == "$_mnt" ]; then + if [[ "$_rmnt" == "$_mnt" ]]; then echo $_mnt/$_path fi } @@ -941,13 +941,13 @@ selinux_relabel() local _path _i _attr _path=$(path_to_be_relabeled) - if [ -z "$_path" ] || ! [ -d "$_path" ] ; then + if [[ -z "$_path" ]] || ! [[ -d "$_path" ]] ; then return fi while IFS= read -r -d '' _i; do _attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null) - if [ -z "$_attr" ]; then + if [[ -z "$_attr" ]]; then restorecon "$_i"; fi done < <(find "$_path" -print0) @@ -960,13 +960,13 @@ check_fence_kdump_config() local nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in $nodes; do - if [ "$node" = "$hostname" ]; then + if [[ "$node" = "$hostname" ]]; then derror "Option fence_kdump_nodes cannot contain $hostname" return 1 fi # node can be ipaddr echo "$ipaddrs " | grep -q "$node " - if [ $? -eq 0 ]; then + if [[ $? -eq 0 ]]; then derror "Option fence_kdump_nodes cannot contain $node" return 1 fi @@ -977,7 +977,7 @@ check_fence_kdump_config() check_dump_feasibility() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then return 0 fi @@ -999,7 +999,7 @@ start_fadump() start_dump() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then start_fadump else load_kdump @@ -1017,14 +1017,14 @@ check_failure_action_config() default_option=$(kdump_get_conf_val default) failure_action=$(kdump_get_conf_val failure_action) - if [ -z "$failure_action" -a -z "$default_option" ]; then + if [[ -z "$failure_action" ]] && [[ -z "$default_option" ]]; then return 0 - elif [ -n "$failure_action" -a -n "$default_option" ]; then + elif [[ -n "$failure_action" ]] && [[ -n "$default_option" ]]; then derror "Cannot specify 'failure_action' and 'default' option together" return 1 fi - if [ -n "$default_option" ]; then + if [[ -n "$default_option" ]]; then option="default" failure_action="$default_option" fi @@ -1044,7 +1044,7 @@ check_final_action_config() local final_action final_action=$(kdump_get_conf_val final_action) - if [ -z "$final_action" ]; then + if [[ -z "$final_action" ]]; then return 0 else case "$final_action" in @@ -1061,13 +1061,13 @@ check_final_action_config() start() { check_dump_feasibility - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi check_config - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1077,13 +1077,13 @@ start() fi save_raw - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi check_current_status - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then dwarn "Kdump already running: [WARNING]" return 0 fi @@ -1096,13 +1096,13 @@ start() fi check_rebuild - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi start_dump - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1113,18 +1113,18 @@ start() reload() { check_current_status - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then dwarn "Kdump was not running: [WARNING]" fi - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then reload_fadump return $? else stop_kdump fi - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Stopping kdump: [FAILED]" return 1 fi @@ -1132,13 +1132,13 @@ reload() dinfo "Stopping kdump: [OK]" setup_initrd - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi start_dump - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1166,7 +1166,7 @@ stop_kdump() $KEXEC -p -u fi - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "kexec: failed to unload kdump kernel" return 1 fi @@ -1178,7 +1178,7 @@ stop_kdump() reload_fadump() { echo 1 > $FADUMP_REGISTER_SYS_NODE - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then dinfo "fadump: re-registered successfully" return 0 else @@ -1186,7 +1186,7 @@ reload_fadump() # support is not enabled. Try stop/start from userspace # to handle such scenario. stop_fadump - if [ $? == 0 ]; then + if [[ $? == 0 ]]; then start_fadump return $? fi @@ -1197,13 +1197,13 @@ reload_fadump() stop() { - if [ $DEFAULT_DUMP_MODE == "fadump" ]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then stop_fadump else stop_kdump fi - if [ $? != 0 ]; then + if [[ $? != 0 ]]; then derror "Stopping kdump: [FAILED]" return 1 fi @@ -1214,7 +1214,7 @@ stop() rebuild() { check_config - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi @@ -1225,7 +1225,7 @@ rebuild() { fi setup_initrd - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then return 1 fi @@ -1242,7 +1242,7 @@ do_estimate() { local size_mb=$(( 1024 * 1024 )) setup_initrd - if [ ! -f "$TARGET_INITRD" ]; then + if [[ ! -f "$TARGET_INITRD" ]]; then derror "kdumpctl estimate: kdump initramfs is not built yet." exit 1 fi @@ -1359,7 +1359,7 @@ reset_crashkernel() { fi } -if [ ! -f "$KDUMP_CONFIG_FILE" ]; then +if [[ ! -f "$KDUMP_CONFIG_FILE" ]]; then derror "Error: No kdump config file found!" exit 1 fi @@ -1371,7 +1371,7 @@ main () case "$1" in start) - if [ -s /proc/vmcore ]; then + if [[ -s /proc/vmcore ]]; then save_core reboot else diff --git a/mkdumprd b/mkdumprd index 6621e30..3101d3f 100644 --- a/mkdumprd +++ b/mkdumprd @@ -6,7 +6,7 @@ # Written by Cong Wang # -if [ -f /etc/sysconfig/kdump ]; then +if [[ -f /etc/sysconfig/kdump ]]; then . /etc/sysconfig/kdump fi @@ -18,7 +18,7 @@ export IN_KDUMP=1 #initiate the kdump logger dlog_init -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then echo "failed to initiate the kdump logger." exit 1 fi @@ -73,7 +73,7 @@ to_mount() { else # for non-nfs _target converting to use udev persistent name _pdev="$(kdump_get_persistent_dev $_target)" - if [ -z "$_pdev" ]; then + if [[ -z "$_pdev" ]]; then return 1 fi fi @@ -116,14 +116,14 @@ mkdir_save_path_ssh() _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) ssh -qn "${_opt[@]}" $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null _ret=$? - if [ $_ret -ne 0 ]; then + if [[ $_ret -ne 0 ]]; then perror_exit "mkdir failed on $1:$SAVE_PATH" fi #check whether user has write permission on $1:$SAVE_PATH _dir=$(ssh -qn "${_opt[@]}" $1 mktemp -dqp $SAVE_PATH 2>/dev/null) _ret=$? - if [ $_ret -ne 0 ]; then + if [[ $_ret -ne 0 ]]; then perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" fi ssh -qn "${_opt[@]}" $1 rmdir $_dir @@ -164,11 +164,11 @@ check_size() { return esac - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then perror_exit "Check dump target size failed" fi - if [ $avail -lt $memtotal ]; then + if [[ $avail -lt $memtotal ]]; then dwarn "Warning: There might not be enough space to save a vmcore." dwarn " The size of $2 should be greater than $memtotal kilo bytes." fi @@ -178,7 +178,7 @@ check_save_path_fs() { local _path=$1 - if [ ! -d $_path ]; then + if [[ ! -d $_path ]]; then perror_exit "Dump path $_path does not exist." fi } @@ -190,7 +190,7 @@ mount_failure() local _fstype=$3 local msg="Failed to mount $_target" - if [ -n "$_mnt" ]; then + if [[ -n "$_mnt" ]]; then msg="$msg on $_mnt" fi @@ -210,11 +210,11 @@ check_user_configured_target() local _opt=$(get_mntopt_from_target $_target) local _fstype=$(get_fs_type_from_target $_target) - if [ -n "$_fstype" ]; then + if [[ -n "$_fstype" ]]; then # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf [[ $_fstype = "nfs"* ]] && _fstype=nfs - if [ -n "$_cfg_fs_type" ] && [ "$_fstype" != "$_cfg_fs_type" ]; then + if [[ -n "$_cfg_fs_type" ]] && [[ "$_fstype" != "$_cfg_fs_type" ]]; then perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\"" fi else @@ -224,11 +224,11 @@ check_user_configured_target() # For noauto mount, mount it inplace with default value. # Else use the temporary target directory - if [ -n "$_mnt" ]; then + if [[ -n "$_mnt" ]]; then if ! is_mounted "$_mnt"; then if [[ $_opt = *",noauto"* ]]; then mount $_mnt - [ $? -ne 0 ] && mount_failure "$_target" "$_mnt" "$_fstype" + [[ $? -ne 0 ]] && mount_failure "$_target" "$_mnt" "$_fstype" _mounted=$_mnt else perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" @@ -238,19 +238,19 @@ check_user_configured_target() _mnt=$MKDUMPRD_TMPMNT mkdir -p $_mnt mount $_target $_mnt -t $_fstype -o defaults - [ $? -ne 0 ] && mount_failure "$_target" "" "$_fstype" + [[ $? -ne 0 ]] && mount_failure "$_target" "" "$_fstype" _mounted=$_mnt fi # For user configured target, use $SAVE_PATH as the dump path within the target - if [ ! -d "$_mnt/$SAVE_PATH" ]; then + if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\"" fi check_size fs "$_target" # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway - if [ -n "$_mounted" ]; then + if [[ -n "$_mounted" ]]; then umount -f -- $_mounted fi } @@ -260,7 +260,7 @@ verify_core_collector() { local _cmd="${1%% *}" local _params="${1#* }" - if [ "$_cmd" != "makedumpfile" ]; then + if [[ "$_cmd" != "makedumpfile" ]]; then if is_raw_dump_target; then dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually." fi @@ -284,7 +284,7 @@ verify_core_collector() { add_mount() { local _mnt=$(to_mount $@) - if [ $? -ne 0 ]; then + if [[ $? -ne 0 ]]; then exit 1 fi @@ -316,7 +316,7 @@ for_each_block_target() local dev majmin for dev in $(get_kdump_targets); do - [ -b "$dev" ] || continue + [[ -b "$dev" ]] || continue majmin=$(get_maj_min $dev) check_block_and_slaves $1 $majmin && return 1 done @@ -331,10 +331,10 @@ is_unresettable() local path="/sys/$(udevadm info --query=all --path=/sys/dev/block/$1 | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" local resettable=1 - if [ -f "$path" ] + if [[ -f "$path" ]] then resettable="$(<"$path")" - [ $resettable -eq 0 -a "$OVERRIDE_RESETTABLE" -eq 0 ] && { + [[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && { local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}') derror "Error: Can not save vmcore because device $device is unresettable" return 0 @@ -359,7 +359,7 @@ check_resettable() for_each_block_target is_unresettable _ret=$? - [ $_ret -eq 0 ] && return + [[ $_ret -eq 0 ]] && return return 1 } @@ -385,7 +385,7 @@ fi # firstly get right SSH_KEY_LOCATION keyfile=$(kdump_get_conf_val sshkey) -if [ -f "$keyfile" ]; then +if [[ -f "$keyfile" ]]; then # canonicalize the path SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile) fi @@ -407,7 +407,7 @@ do perror_exit "Bad raw disk $config_val" } _praw=$(persistent_policy="by-id" kdump_get_persistent_dev $config_val) - if [ -z "$_praw" ]; then + if [[ -z "$_praw" ]]; then exit 1 fi add_dracut_arg "--device" "$_praw" @@ -438,7 +438,7 @@ done <<< "$(kdump_read_conf)" handle_default_dump_target -if [ -n "$extra_modules" ] +if [[ -n "$extra_modules" ]] then add_dracut_arg "--add-drivers" "$extra_modules" fi diff --git a/mkfadumprd b/mkfadumprd index 5c87933..ca9f362 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -2,7 +2,7 @@ # Generate an initramfs image that isolates dump capture capability within # the default initramfs using zz-fadumpinit dracut module. -if [ -f /etc/sysconfig/kdump ]; then +if [[ -f /etc/sysconfig/kdump ]]; then . /etc/sysconfig/kdump fi From 86538ca6e2e555caa8cdd2bcfcc3c5e94ac6bf58 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 17:21:41 +0800 Subject: [PATCH 123/454] bash scripts: fix variable quoting issue Fixed quoting issues found by shellcheck, no feature change. This should fix many errors when there is space in any shell variables, eg. dump target's name/path/id. False positives are marked with "# shellcheck disable=SCXXXX", for example, args are expected to split so it should not be quoted. And replaced some `cut -d ' ' -fX` with `awk '{print $X}'` since cut is fragile, and doesn't work well with any quoted strings that have redundant space. Following quoting related issues are fixed (check the link for example code and what could go wrong): https://github.com/koalaman/shellcheck/wiki/SC2046 https://github.com/koalaman/shellcheck/wiki/SC2053 https://github.com/koalaman/shellcheck/wiki/SC2068 https://github.com/koalaman/shellcheck/wiki/SC2086 https://github.com/koalaman/shellcheck/wiki/SC2206 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-early-kdump-module-setup.sh | 2 +- dracut-module-setup.sh | 261 +++++++++++++++-------------- kdumpctl | 104 ++++++------ mkdumprd | 69 ++++---- 4 files changed, 220 insertions(+), 216 deletions(-) diff --git a/dracut-early-kdump-module-setup.sh b/dracut-early-kdump-module-setup.sh index 00546e0..83e067c 100755 --- a/dracut-early-kdump-module-setup.sh +++ b/dracut-early-kdump-module-setup.sh @@ -25,7 +25,7 @@ prepare_kernel_initrd() { prepare_kdump_bootinfo # $kernel is a variable from dracut - if [[ "$KDUMP_KERNELVER" != $kernel ]]; then + if [[ "$KDUMP_KERNELVER" != "$kernel" ]]; then dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \ "but the initramfs is generated for kernel version '$kernel'" fi diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 515cff0..07a96e5 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -53,7 +53,7 @@ depends() { _dep="$_dep network" fi - echo $_dep + echo "$_dep" } kdump_is_bridge() { @@ -65,7 +65,7 @@ kdump_is_bond() { } kdump_is_team() { - [[ -f /usr/bin/teamnl ]] && teamnl $1 ports &> /dev/null + [[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null } kdump_is_vlan() { @@ -77,9 +77,9 @@ source_ifcfg_file() { local ifcfg_file dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." - ifcfg_file=$(get_ifcfg_filename $1) + ifcfg_file=$(get_ifcfg_filename "$1") if [[ -f "${ifcfg_file}" ]]; then - . ${ifcfg_file} + . "${ifcfg_file}" else dwarning "The ifcfg file of $1 is not found!" fi @@ -93,7 +93,8 @@ kdump_setup_dns() { local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf _tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS") - array=(${_tmp//|/ }) + # shellcheck disable=SC2206 + array=( ${_tmp//|/ } ) if [[ ${array[*]} ]]; then for _dns in "${array[@]}" do @@ -108,10 +109,10 @@ kdump_setup_dns() { while read -r content; do - _nameserver=$(echo $content | grep ^nameserver) + _nameserver=$(echo "$content" | grep ^nameserver) [[ -z "$_nameserver" ]] && continue - _dns=$(echo $_nameserver | cut -d' ' -f2) + _dns=$(echo "$_nameserver" | awk '{print $2}') [[ -z "$_dns" ]] && continue if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then @@ -237,14 +238,14 @@ kdump_static_ip() { local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag local _netmask _gateway _ipaddr _target _nexthop _prefix - _ipaddr=$(ip addr show dev $_netdev permanent | awk "/ $_srcaddr\/.* /{print \$2}") + _ipaddr=$(ip addr show dev "$_netdev" permanent | awk "/ $_srcaddr\/.* /{print \$2}") - if is_ipv6_address $_srcaddr; then + if is_ipv6_address "$_srcaddr"; then _ipv6_flag="-6" fi if [[ -n "$_ipaddr" ]]; then - _gateway=$(ip $_ipv6_flag route list dev $_netdev | \ + _gateway=$(ip $_ipv6_flag route list dev "$_netdev" | \ awk '/^default /{print $3}' | head -n 1) if [[ "x" != "x"$_ipv6_flag ]]; then @@ -266,23 +267,23 @@ kdump_static_ip() { /sbin/ip $_ipv6_flag route show | grep -v default |\ grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\ while read -r _route; do - _target=$(echo $_route | cut -d ' ' -f1) - _nexthop=$(echo $_route | cut -d ' ' -f3) + _target=$(echo "$_route" | awk '{print $1}') + _nexthop=$(echo "$_route" | awk '{print $3}') if [[ "x" != "x"$_ipv6_flag ]]; then _target="[$_target]" _nexthop="[$_nexthop]" fi echo "rd.route=$_target:$_nexthop:$kdumpnic" - done >> ${initdir}/etc/cmdline.d/45route-static.conf + done >> "${initdir}/etc/cmdline.d/45route-static.conf" - kdump_handle_mulitpath_route $_netdev $_srcaddr $kdumpnic + kdump_handle_mulitpath_route "$_netdev" "$_srcaddr" "$kdumpnic" } kdump_handle_mulitpath_route() { local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag local _target _nexthop _route _weight _max_weight _rule - if is_ipv6_address $_srcaddr; then + if is_ipv6_address "$_srcaddr"; then _ipv6_flag="-6" fi @@ -308,20 +309,20 @@ kdump_handle_mulitpath_route() { _target=$(echo "$_route" | cut -d ' ' -f1) _rule="" _max_weight=0 _weight=0 fi - done >> ${initdir}/etc/cmdline.d/45route-static.conf\ + done >> "${initdir}/etc/cmdline.d/45route-static.conf"\ <<< "$(/sbin/ip $_ipv6_flag route show)" - [[ -n $_rule ]] && echo $_rule >> ${initdir}/etc/cmdline.d/45route-static.conf + [[ -n $_rule ]] && echo "$_rule" >> "${initdir}/etc/cmdline.d/45route-static.conf" } kdump_get_mac_addr() { - cat /sys/class/net/$1/address + cat "/sys/class/net/$1/address" } #Bonding or team master modifies the mac address #of its slaves, we should use perm address kdump_get_perm_addr() { - local addr=$(ethtool -P $1 | sed -e 's/Permanent address: //') + local addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //') if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]] then derror "Can't get the permanent address of $1" @@ -367,9 +368,9 @@ kdump_setup_bridge() { elif kdump_is_vlan "$_dev"; then kdump_setup_vlan "$_dev" else - _mac=$(kdump_get_mac_addr $_dev) - _kdumpdev=$(kdump_setup_ifname $_dev) - echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/41bridge.conf + _mac=$(kdump_get_mac_addr "$_dev") + _kdumpdev=$(kdump_setup_ifname "$_dev") + echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/41bridge.conf" fi _brif+="$_kdumpdev," done @@ -383,10 +384,10 @@ kdump_setup_bond() { local _netdev="$1" local _nm_show_cmd="$2" local _dev _mac _slaves _kdumpdev _bondoptions - for _dev in $(cat /sys/class/net/$_netdev/bonding/slaves); do - _mac=$(kdump_get_perm_addr $_dev) - _kdumpdev=$(kdump_setup_ifname $_dev) - echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf + for _dev in $(cat "/sys/class/net/$_netdev/bonding/slaves"); do + _mac=$(kdump_get_perm_addr "$_dev") + _kdumpdev=$(kdump_setup_ifname "$_dev") + echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/42bond.conf" _slaves+="$_kdumpdev," done echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf" @@ -395,8 +396,8 @@ kdump_setup_bond() { if [[ -z "$_bondoptions" ]]; then dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." - source_ifcfg_file $_netdev - _bondoptions="$(echo $BONDING_OPTS | xargs echo | tr " " ",")" + source_ifcfg_file "$_netdev" + _bondoptions="$(echo "$BONDING_OPTS" | xargs echo | tr " " ",")" fi if [[ -z "$_bondoptions" ]]; then @@ -404,36 +405,36 @@ kdump_setup_bond() { exit 1 fi - echo ":$_bondoptions" >> ${initdir}/etc/cmdline.d/42bond.conf + echo ":$_bondoptions" >> "${initdir}/etc/cmdline.d/42bond.conf" } kdump_setup_team() { local _netdev=$1 local _dev _mac _slaves _kdumpdev - for _dev in $(teamnl $_netdev ports | awk -F':' '{print $2}'); do - _mac=$(kdump_get_perm_addr $_dev) - _kdumpdev=$(kdump_setup_ifname $_dev) - echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf + for _dev in $(teamnl "$_netdev" ports | awk -F':' '{print $2}'); do + _mac=$(kdump_get_perm_addr "$_dev") + _kdumpdev=$(kdump_setup_ifname "$_dev") + echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/44team.conf" _slaves+="$_kdumpdev," done echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf" #Buggy version teamdctl outputs to stderr! #Try to use the latest version of teamd. - teamdctl "$_netdev" config dump > ${initdir}/tmp/$$-$_netdev.conf + teamdctl "$_netdev" config dump > "${initdir}/tmp/$$-$_netdev.conf" if [[ $? -ne 0 ]] then derror "teamdctl failed." exit 1 fi inst_dir /etc/teamd - inst_simple ${initdir}/tmp/$$-$_netdev.conf "/etc/teamd/$_netdev.conf" - rm -f ${initdir}/tmp/$$-$_netdev.conf + inst_simple "${initdir}/tmp/$$-$_netdev.conf" "/etc/teamd/$_netdev.conf" + rm -f "${initdir}/tmp/$$-$_netdev.conf" } kdump_setup_vlan() { local _netdev=$1 local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" - local _netmac="$(kdump_get_mac_addr $_phydev)" + local _netmac="$(kdump_get_mac_addr "$_phydev")" local _kdumpdev #Just support vlan over bond and team @@ -445,10 +446,10 @@ kdump_setup_vlan() { if [[ $? != 0 ]]; then exit 1 fi - echo " vlan=$(kdump_setup_ifname $_netdev):$_phydev" > ${initdir}/etc/cmdline.d/43vlan.conf + echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" else - _kdumpdev="$(kdump_setup_ifname $_phydev)" - echo " vlan=$(kdump_setup_ifname $_netdev):$_kdumpdev ifname=$_kdumpdev:$_netmac" > ${initdir}/etc/cmdline.d/43vlan.conf + _kdumpdev="$(kdump_setup_ifname "$_phydev")" + echo " vlan=$(kdump_setup_ifname "$_netdev"):$_kdumpdev ifname=$_kdumpdev:$_netmac" > "${initdir}/etc/cmdline.d/43vlan.conf" fi } @@ -465,7 +466,7 @@ find_online_znet_device() { for d in $NETWORK_DEVICES do [[ ! -f "$d/online" ]] && continue - read -r ONLINE < $d/online + read -r ONLINE < "$d/online" if [[ $ONLINE -ne 1 ]]; then continue fi @@ -473,10 +474,10 @@ find_online_znet_device() { # device is online) if [[ -f $d/if_name ]] then - read -r ifname < $d/if_name + read -r ifname < "$d/if_name" elif [[ -d $d/net ]] then - ifname=$(ls $d/net/) + ifname=$(ls "$d/net/") fi [[ -n "$ifname" ]] && break done @@ -500,7 +501,7 @@ kdump_setup_znet() { if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script." - source_ifcfg_file $_netdev + source_ifcfg_file "$_netdev" for i in $OPTIONS; do _options=${_options},$i done @@ -510,17 +511,17 @@ kdump_setup_znet() { exit 1 fi - echo rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS} > ${initdir}/etc/cmdline.d/30znet.conf + echo "rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS}" > "${initdir}/etc/cmdline.d/30znet.conf" } kdump_get_ip_route() { - local _route=$(/sbin/ip -o route get to $1 2>&1) + local _route=$(/sbin/ip -o route get to "$1" 2>&1) if [[ $? != 0 ]]; then derror "Bad kdump network destination: $1" exit 1 fi - echo $_route + echo "$_route" } kdump_get_ip_route_field() @@ -530,15 +531,15 @@ kdump_get_ip_route_field() kdump_get_remote_ip() { - local _remote=$(get_remote_host $1) _remote_temp - if is_hostname $_remote; then - _remote_temp=$(getent ahosts $_remote | grep -v : | head -n 1) + local _remote=$(get_remote_host "$1") _remote_temp + if is_hostname "$_remote"; then + _remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1) if [[ -z "$_remote_temp" ]]; then - _remote_temp=$(getent ahosts $_remote | head -n 1) + _remote_temp=$(getent ahosts "$_remote" | head -n 1) fi - _remote=$(echo $_remote_temp | cut -d' ' -f1) + _remote=$(echo "$_remote_temp" | awk '{print $1}') fi - echo $_remote + echo "$_remote" } # Setup dracut to bring up network interface that enable @@ -549,13 +550,13 @@ kdump_install_net() { local _static _proto _ip_conf _ip_opts _ifname_opts local _znet_netdev _nm_show_cmd_znet - _destaddr=$(kdump_get_remote_ip $1) - _route=$(kdump_get_ip_route $_destaddr) + _destaddr=$(kdump_get_remote_ip "$1") + _route=$(kdump_get_ip_route "$_destaddr") _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") _nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev") - _netmac=$(kdump_get_mac_addr $_netdev) - kdumpnic=$(kdump_setup_ifname $_netdev) + _netmac=$(kdump_get_mac_addr "$_netdev") + kdumpnic=$(kdump_setup_ifname "$_netdev") _znet_netdev=$(find_online_znet_device) if [[ -n "$_znet_netdev" ]]; then @@ -567,10 +568,10 @@ kdump_install_net() { fi fi - _static=$(kdump_static_ip $_netdev $_srcaddr $kdumpnic) + _static=$(kdump_static_ip "$_netdev" "$_srcaddr" "$kdumpnic") if [[ -n "$_static" ]]; then _proto=none - elif is_ipv6_address $_srcaddr; then + elif is_ipv6_address "$_srcaddr"; then _proto=auto6 else _proto=dhcp @@ -583,9 +584,9 @@ kdump_install_net() { # so we have to avoid adding duplicates # We should also check /proc/cmdline for existing ip=xx arg. # For example, iscsi boot will specify ip=xxx arg in cmdline. - if [[ ! -f $_ip_conf ]] || ! grep -q $_ip_opts $_ip_conf &&\ + if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" &&\ ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then - echo "$_ip_opts" >> $_ip_conf + echo "$_ip_opts" >> "$_ip_conf" fi if kdump_is_bridge "$_netdev"; then @@ -601,14 +602,14 @@ kdump_install_net() { kdump_setup_vlan "$_netdev" else _ifname_opts=" ifname=$kdumpnic:$_netmac" - echo "$_ifname_opts" >> $_ip_conf + echo "$_ifname_opts" >> "$_ip_conf" fi kdump_setup_dns "$_netdev" "$_nm_show_cmd" if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then # network-manager module needs this parameter - echo "rd.neednet" >> ${initdir}/etc/cmdline.d/50neednet.conf + echo "rd.neednet" >> "${initdir}/etc/cmdline.d/50neednet.conf" fi # Save netdev used for kdump as cmdline @@ -620,8 +621,8 @@ kdump_install_net() { # gateway. if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] && [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then - echo "kdumpnic=$kdumpnic" > ${initdir}/etc/cmdline.d/60kdumpnic.conf - echo "bootdev=$kdumpnic" > ${initdir}/etc/cmdline.d/70bootdev.conf + echo "kdumpnic=$kdumpnic" > "${initdir}/etc/cmdline.d/60kdumpnic.conf" + echo "bootdev=$kdumpnic" > "${initdir}/etc/cmdline.d/70bootdev.conf" fi } @@ -630,7 +631,7 @@ kdump_install_pre_post_conf() { if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do if [[ -x "$file" ]]; then - dracut_install $file + dracut_install "$file" elif [[ $file != "/etc/kdump/pre.d/*" ]]; then echo "$file is not executable" fi @@ -640,7 +641,7 @@ kdump_install_pre_post_conf() { if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do if [[ -x "$file" ]]; then - dracut_install $file + dracut_install "$file" elif [[ $file != "/etc/kdump/post.d/*" ]]; then echo "$file is not executable" fi @@ -655,19 +656,19 @@ default_dump_target_install_conf() is_user_configured_dump_target && return - _save_path=$(get_bind_mount_source $(get_save_path)) - _target=$(get_target_from_path $_save_path) - _mntpoint=$(get_mntpoint_from_target $_target) + _save_path=$(get_bind_mount_source "$(get_save_path)") + _target=$(get_target_from_path "$_save_path") + _mntpoint=$(get_mntpoint_from_target "$_target") - _fstype=$(get_fs_type_from_target $_target) - if is_fs_type_nfs $_fstype; then + _fstype=$(get_fs_type_from_target "$_target") + if is_fs_type_nfs "$_fstype"; then kdump_install_net "$_target" _fstype="nfs" else - _target=$(kdump_get_persistent_dev $_target) + _target=$(kdump_get_persistent_dev "$_target") fi - echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf + echo "$_fstype $_target" >> "${initdir}/tmp/$$-kdump.conf" # don't touch the path under root mount if [[ "$_mntpoint" != "/" ]]; then @@ -675,8 +676,8 @@ default_dump_target_install_conf() fi #erase the old path line, then insert the parsed path - sed -i "/^path/d" ${initdir}/tmp/$$-kdump.conf - echo "path $_save_path" >> ${initdir}/tmp/$$-kdump.conf + sed -i "/^path/d" "${initdir}/tmp/$$-kdump.conf" + echo "path $_save_path" >> "${initdir}/tmp/$$-kdump.conf" } #install kdump.conf and what user specifies in kdump.conf @@ -690,12 +691,12 @@ kdump_install_conf() { # remove inline comments after the end of a directive. case "$_opt" in raw) - _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev $_val) - sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf + _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val") + sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" ;; ext[234]|xfs|btrfs|minix) - _pdev=$(kdump_get_persistent_dev $_val) - sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf + _pdev=$(kdump_get_persistent_dev "$_val") + sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" ;; ssh|nfs) kdump_install_net "$_val" @@ -706,7 +707,7 @@ kdump_install_conf() { fi ;; kdump_pre|kdump_post|extra_bins) - dracut_install $_val + dracut_install "$_val" ;; core_collector) dracut_install "${_val%%[[:blank:]]*}" @@ -720,7 +721,7 @@ kdump_install_conf() { kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf" inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf" - rm -f ${initdir}/tmp/$$-kdump.conf + rm -f "${initdir}/tmp/$$-kdump.conf" } # Default sysctl parameters should suffice for kdump kernel. @@ -742,9 +743,9 @@ kdump_iscsi_get_rec_val() { # The open-iscsi 742 release changed to using flat files in # /var/lib/iscsi. - result=$(/sbin/iscsiadm --show -m session -r ${1} | grep "^${2} = ") + result=$(/sbin/iscsiadm --show -m session -r "$1" | grep "^${2} = ") result=${result##* = } - echo $result + echo "$result" } kdump_get_iscsi_initiator() { @@ -770,7 +771,7 @@ kdump_get_iscsi_initiator() { # Figure out iBFT session according to session type is_ibft() { - [[ "$(kdump_iscsi_get_rec_val $1 "node.discovery_type")" = fw ]] + [[ "$(kdump_iscsi_get_rec_val "$1" "node.discovery_type")" = fw ]] } kdump_setup_iscsi_device() { @@ -786,32 +787,32 @@ kdump_setup_iscsi_device() { # Check once before getting explicit values, so we can bail out early, # e.g. in case of pure-hardware(all-offload) iscsi. - if ! /sbin/iscsiadm -m session -r ${path} &>/dev/null ; then + if ! /sbin/iscsiadm -m session -r "$path" &>/dev/null ; then return 1 fi - if is_ibft ${path}; then + if is_ibft "$path"; then return fi # Remove software iscsi cmdline generated by 95iscsi, # and let kdump regenerate here. - rm -f ${initdir}/etc/cmdline.d/95iscsi.conf + rm -f "${initdir}/etc/cmdline.d/95iscsi.conf" - tgt_name=$(kdump_iscsi_get_rec_val ${path} "node.name") - tgt_ipaddr=$(kdump_iscsi_get_rec_val ${path} "node.conn\[0\].address") + tgt_name=$(kdump_iscsi_get_rec_val "$path" "node.name") + tgt_ipaddr=$(kdump_iscsi_get_rec_val "$path" "node.conn\[0\].address") # get and set username and password details - username=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username") + username=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username") [[ "$username" == "" ]] && username="" - password=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password") + password=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password") [[ "$password" == "" ]] && password="" - username_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.username_in") + username_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username_in") [[ -n "$username" ]] && userpwd_str="$username:$password" # get and set incoming username and password details [[ "$username_in" == "" ]] && username_in="" - password_in=$(kdump_iscsi_get_rec_val ${path} "node.session.auth.password_in") + password_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password_in") [[ "$password_in" == "" ]] && password_in="" [[ -n "$username_in" ]] && userpwd_in_str=":$username_in:$password_in" @@ -822,16 +823,16 @@ kdump_setup_iscsi_device() { # FIXME: Do we need to parse and set other parameters like protocol, port # iscsi_iface_name, netdev_name, LUN etc. - if is_ipv6_address $tgt_ipaddr; then + if is_ipv6_address "$tgt_ipaddr"; then tgt_ipaddr="[$tgt_ipaddr]" fi netroot_str="netroot=iscsi:${userpwd_str}${userpwd_in_str}@$tgt_ipaddr::::$tgt_name" - [[ -f $netroot_conf ]] || touch $netroot_conf + [[ -f $netroot_conf ]] || touch "$netroot_conf" # If netroot target does not exist already, append. - if ! grep -q $netroot_str $netroot_conf; then - echo $netroot_str >> $netroot_conf + if ! grep -q "$netroot_str" "$netroot_conf"; then + echo "$netroot_str" >> "$netroot_conf" dinfo "Appended $netroot_str to $netroot_conf" fi @@ -840,9 +841,9 @@ kdump_setup_iscsi_device() { [[ $? -ne "0" ]] && derror "Failed to get initiator name" && return 1 # If initiator details do not exist already, append. - if ! grep -q "$initiator_str" $netroot_conf; then - echo "$initiator_str" >> $netroot_conf - dinfo "Appended "$initiator_str" to $netroot_conf" + if ! grep -q "$initiator_str" "$netroot_conf"; then + echo "$initiator_str" >> "$netroot_conf" + dinfo "Appended $initiator_str to $netroot_conf" fi } @@ -877,13 +878,13 @@ get_alias() { for ip in $ips do # in /etc/hosts, alias can come at the 2nd column - entries=$(grep $ip /etc/hosts | awk '{ $1=""; print $0 }') + entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }') if [[ $? -eq 0 ]]; then alias_set="$alias_set $entries" fi done - echo $alias_set + echo "$alias_set" } is_localhost() { @@ -914,23 +915,23 @@ get_pcs_fence_kdump_nodes() { # we need to convert each to node1, node2 ... nodeX in each iteration for node in ${nodelist}; do # convert $node from 'uname="nodeX"' to 'nodeX' - eval $node - nodename=$uname + eval "$node" + nodename="$uname" # Skip its own node name - if is_localhost $nodename; then + if is_localhost "$nodename"; then continue fi nodes="$nodes $nodename" done - echo $nodes + echo "$nodes" } # retrieves fence_kdump args from config file get_pcs_fence_kdump_args() { if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then - . $FENCE_KDUMP_CONFIG_FILE - echo $FENCE_KDUMP_OPTS + . "$FENCE_KDUMP_CONFIG_FILE" + echo "$FENCE_KDUMP_OPTS" fi } @@ -941,12 +942,12 @@ get_generic_fence_kdump_nodes() { nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in ${nodes}; do # Skip its own node name - if is_localhost $node; then + if is_localhost "$node"; then continue fi filtered="$filtered $node" done - echo $filtered + echo "$filtered" } # setup fence_kdump in cluster @@ -963,11 +964,11 @@ kdump_configure_fence_kdump () { nodes=$(get_pcs_fence_kdump_nodes) # set appropriate options in kdump.conf - echo "fence_kdump_nodes $nodes" >> ${kdump_cfg_file} + echo "fence_kdump_nodes $nodes" >> "${kdump_cfg_file}" args=$(get_pcs_fence_kdump_args) if [[ -n "$args" ]]; then - echo "fence_kdump_args $args" >> ${kdump_cfg_file} + echo "fence_kdump_args $args" >> "${kdump_cfg_file}" fi else @@ -977,12 +978,12 @@ kdump_configure_fence_kdump () { # setup network for each node for node in ${nodes}; do - kdump_install_net $node + kdump_install_net "$node" done dracut_install /etc/hosts dracut_install /etc/nsswitch.conf - dracut_install $FENCE_KDUMP_SEND + dracut_install "$FENCE_KDUMP_SEND" } # Install a random seed used to feed /dev/urandom @@ -992,32 +993,32 @@ kdump_install_random_seed() { poolsize=$( /dev/null + dd if=/dev/urandom of="${initdir}/var/lib/random-seed" \ + bs="$poolsize" count=1 2> /dev/null } kdump_install_systemd_conf() { # Kdump turns out to require longer default systemd mount timeout # than 1st kernel(90s by default), we use default 300s for kdump. - grep -r "^[[:space:]]*DefaultTimeoutStartSec=" ${initdir}/etc/systemd/system.conf* &>/dev/null + grep -r "^[[:space:]]*DefaultTimeoutStartSec=" "${initdir}/etc/systemd/system.conf"* &>/dev/null if [[ $? -ne 0 ]]; then - mkdir -p ${initdir}/etc/systemd/system.conf.d - echo "[Manager]" > ${initdir}/etc/systemd/system.conf.d/kdump.conf - echo "DefaultTimeoutStartSec=300s" >> ${initdir}/etc/systemd/system.conf.d/kdump.conf + mkdir -p "${initdir}/etc/systemd/system.conf.d" + echo "[Manager]" > "${initdir}/etc/systemd/system.conf.d/kdump.conf" + echo "DefaultTimeoutStartSec=300s" >> "${initdir}/etc/systemd/system.conf.d/kdump.conf" fi # Forward logs to console directly, and don't read Kmsg, this avoids # unneccessary memory consumption and make console output more useful. # Only do so for non fadump image. - mkdir -p ${initdir}/etc/systemd/journald.conf.d - echo "[Journal]" > ${initdir}/etc/systemd/journald.conf.d/kdump.conf - echo "Storage=volatile" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf - echo "ReadKMsg=no" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf - echo "ForwardToConsole=yes" >> ${initdir}/etc/systemd/journald.conf.d/kdump.conf + mkdir -p "${initdir}/etc/systemd/journald.conf.d" + echo "[Journal]" > "${initdir}/etc/systemd/journald.conf.d/kdump.conf" + echo "Storage=volatile" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf" + echo "ReadKMsg=no" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf" + echo "ForwardToConsole=yes" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf" } install() { @@ -1030,7 +1031,7 @@ install() { fi dracut_install -o /etc/adjtime /etc/localtime inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress" - chmod +x ${initdir}/kdumpscripts/monitor_dd_progress + chmod +x "${initdir}/kdumpscripts/monitor_dd_progress" inst "/bin/dd" "/bin/dd" inst "/bin/tail" "/bin/tail" inst "/bin/date" "/bin/date" @@ -1076,7 +1077,7 @@ install() { # actually does nothing. sed -i -e \ 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ - ${initdir}/etc/lvm/lvm.conf &>/dev/null + "${initdir}/etc/lvm/lvm.conf" &>/dev/null # Save more memory by dropping switch root capability dracut_no_switch_root diff --git a/kdumpctl b/kdumpctl index 11782df..ed6dc3a 100755 --- a/kdumpctl +++ b/kdumpctl @@ -78,11 +78,11 @@ save_core() { coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" - mkdir -p $coredir + mkdir -p "$coredir" ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" - cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete + cp --sparse=always /proc/vmcore "$coredir/vmcore-incomplete" if [[ $? == 0 ]]; then - mv $coredir/vmcore-incomplete $coredir/vmcore + mv "$coredir/vmcore-incomplete" "$coredir/vmcore" dinfo "saved a vmcore to $coredir" else derror "failed to save a vmcore to $coredir" @@ -93,9 +93,9 @@ save_core() # https://fedorahosted.org/abrt/ if [[ -x /usr/bin/dumpoops ]]; then ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" - makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg >/dev/null 2>&1 + makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" >/dev/null 2>&1 ddebug "dumpoops -d $coredir/dmesg" - dumpoops -d $coredir/dmesg >/dev/null 2>&1 + dumpoops -d "$coredir/dmesg" >/dev/null 2>&1 if [[ $? == 0 ]]; then dinfo "kernel oops has been collected by abrt tool" fi @@ -121,7 +121,7 @@ check_earlykdump_is_enabled() rebuild_kdump_initrd() { ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER" - $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER + $MKDUMPRD "$TARGET_INITRD" "$KDUMP_KERNELVER" if [[ $? != 0 ]]; then derror "mkdumprd: failed to make kdump initrd" return 1 @@ -136,8 +136,8 @@ rebuild_kdump_initrd() rebuild_initrd() { - if [[ ! -w $(dirname $TARGET_INITRD) ]];then - derror "$(dirname $TARGET_INITRD) does not have write permission. Cannot rebuild $TARGET_INITRD" + if [[ ! -w $(dirname "$TARGET_INITRD") ]];then + derror "$(dirname "$TARGET_INITRD") does not have write permission. Cannot rebuild $TARGET_INITRD" return 1 fi @@ -183,11 +183,11 @@ backup_default_initrd() if [[ ! -e $DEFAULT_INITRD_BAK ]]; then dinfo "Backing up $DEFAULT_INITRD before rebuild." # save checksum to verify before restoring - sha1sum $DEFAULT_INITRD > $INITRD_CHECKSUM_LOCATION - cp $DEFAULT_INITRD $DEFAULT_INITRD_BAK + sha1sum "$DEFAULT_INITRD" > "$INITRD_CHECKSUM_LOCATION" + cp "$DEFAULT_INITRD" "$DEFAULT_INITRD_BAK" if [[ $? -ne 0 ]]; then dwarn "WARNING: failed to backup $DEFAULT_INITRD." - rm -f $DEFAULT_INITRD_BAK + rm -f "$DEFAULT_INITRD_BAK" fi fi } @@ -210,7 +210,7 @@ restore_default_initrd() dwarn "WARNING: checksum mismatch! Can't restore original initrd.." else rm -f $INITRD_CHECKSUM_LOCATION - mv $DEFAULT_INITRD_BAK $DEFAULT_INITRD + mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD" if [[ $? -eq 0 ]]; then derror "Restoring original initrd as fadump mode is disabled." sync @@ -226,7 +226,7 @@ check_config() case "$config_opt" in dracut_args) if [[ $config_val == *--mount* ]]; then - if [[ $(echo $config_val | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then + if [[ $(echo "$config_val" | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then derror "Multiple mount targets specified in one \"dracut_args\"." return 1 fi @@ -297,13 +297,13 @@ get_pcs_cluster_modified_files() fi if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then - time_stamp=$(stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE) + time_stamp=$(stat -c "%Y" "$FENCE_KDUMP_CONFIG_FILE") if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE" fi fi - echo $modified_files + echo "$modified_files" } setup_initrd() @@ -314,7 +314,7 @@ setup_initrd() return 1 fi - DEFAULT_INITRD_BAK="$KDUMP_BOOTDIR/.$(basename $DEFAULT_INITRD).default" + DEFAULT_INITRD_BAK="$KDUMP_BOOTDIR/.$(basename "$DEFAULT_INITRD").default" if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then TARGET_INITRD="$DEFAULT_INITRD" @@ -357,7 +357,7 @@ check_files_modified() fi HOOKS="$HOOKS $POST_FILES $PRE_FILES" CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}') - CORE_COLLECTOR=$(type -P $CORE_COLLECTOR) + CORE_COLLECTOR=$(type -P "$CORE_COLLECTOR") # POST_FILES and PRE_FILES are already checked against executable, need not to check again. EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" CHECK_FILES=$(kdump_get_conf_val extra_bins) @@ -375,8 +375,8 @@ check_files_modified() _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)" if [[ $? -eq 0 ]]; then files="$files $_module_file" - for _dep_modules in $(modinfo -F depends $_module | tr ',' ' '); do - files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename $_dep_modules 2>/dev/null)" + for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do + files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2>/dev/null)" done else # If it's not a module nor builtin, give an error @@ -394,13 +394,13 @@ check_files_modified() for file in $files; do if [[ -e "$file" ]]; then - time_stamp=$(stat -c "%Y" $file) + time_stamp=$(stat -c "%Y" "$file") if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $file" fi if [[ -L "$file" ]]; then - file=$(readlink -m $file) - time_stamp=$(stat -c "%Y" $file) + file=$(readlink -m "$file") + time_stamp=$(stat -c "%Y" "$file") if [[ "$time_stamp" -gt "$image_time" ]]; then modified_files="$modified_files $file" fi @@ -453,8 +453,8 @@ check_drivers_modified() ddebug "Modules included in old initramfs: '$_old_drivers'" for _driver in $_new_drivers; do # Skip deprecated/invalid driver name or built-in module - _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name $_driver 2>/dev/null) - _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n $_driver 2>/dev/null) + _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null) + _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2>/dev/null) if [[ $? -ne 0 ]] || [[ -z "$_module_name" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then continue fi @@ -483,21 +483,21 @@ check_fs_modified() fi _target=$(get_block_dump_target) - _new_fstype=$(get_fs_type_from_target $_target) + _new_fstype=$(get_fs_type_from_target "$_target") if [[ -z "$_target" ]] || [[ -z "$_new_fstype" ]];then derror "Dump target is invalid" return 2 fi ddebug "_target=$_target _new_fstype=$_new_fstype" - _new_dev=$(kdump_get_persistent_dev $_target) + _new_dev=$(kdump_get_persistent_dev "$_target") if [[ -z "$_new_dev" ]]; then perror "Get persistent device name failed" return 2 fi - _new_mntpoint="$(get_kdump_mntpoint_from_target $_target)" - _dracut_args=$(lsinitrd $TARGET_INITRD -f usr/lib/dracut/build-parameter.txt) + _new_mntpoint="$(get_kdump_mntpoint_from_target "$_target")" + _dracut_args=$(lsinitrd "$TARGET_INITRD" -f usr/lib/dracut/build-parameter.txt) if [[ -z "$_dracut_args" ]];then dwarn "Warning: No dracut arguments found in initrd" return 0 @@ -505,13 +505,14 @@ check_fs_modified() # if --mount argument present then match old and new target, mount # point and file system. If any of them mismatches then rebuild - echo $_dracut_args | grep -q "\-\-mount" + echo "$_dracut_args" | grep -q "\-\-mount" if [[ $? -eq 0 ]];then - set -- $(echo $_dracut_args | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) + # shellcheck disable=SC2046 + set -- $(echo "$_dracut_args" | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) _old_dev=$1 _old_mntpoint=$2 _old_fstype=$3 - [[ $_new_dev = $_old_dev && $_new_mntpoint = $_old_mntpoint && $_new_fstype = $_old_fstype ]] && return 0 + [[ $_new_dev = "$_old_dev" && $_new_mntpoint = "$_old_mntpoint" && $_new_fstype = "$_old_fstype" ]] && return 0 # otherwise rebuild if target device is not a root device else [[ "$_target" = "$(get_root_fs_device)" ]] && return 0 @@ -590,7 +591,7 @@ check_rebuild() #check to see if dependent files has been modified #since last build of the image file if [[ -f $TARGET_INITRD ]]; then - image_time=$(stat -c "%Y" $TARGET_INITRD 2>/dev/null) + image_time=$(stat -c "%Y" "$TARGET_INITRD" 2>/dev/null) #in case of fadump mode, check whether the default/target #initrd is already built with dump capture capability @@ -649,7 +650,7 @@ function remove_kdump_kernel_key() return fi - keyctl unlink $KDUMP_KEY_ID %:.ima + keyctl unlink "$KDUMP_KEY_ID" %:.ima } # Load the kdump kernel specified in /etc/sysconfig/kdump @@ -682,9 +683,10 @@ load_kdump() PS4='+ $(date "+%Y-%m-%d %H:%M:%S") ${BASH_SOURCE}@${LINENO}: ' set -x + # shellcheck disable=SC2086 $KEXEC $KEXEC_ARGS $standard_kexec_args \ --command-line="$KDUMP_COMMANDLINE" \ - --initrd=$TARGET_INITRD $KDUMP_KERNEL + --initrd="$TARGET_INITRD" "$KDUMP_KERNEL" ret=$? set +x @@ -709,7 +711,7 @@ check_ssh_config() # remove inline comments after the end of a directive. if [[ -f "$config_val" ]]; then # canonicalize the path - SSH_KEY_LOCATION=$(/usr/bin/readlink -m $config_val) + SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val") else dwarn "WARNING: '$config_val' doesn't exist, using default value '$SSH_KEY_LOCATION'" fi @@ -726,7 +728,7 @@ check_ssh_config() done <<< "$(kdump_read_conf)" #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') if [[ -z "$SSH_TARGET" ]]; then return 1 fi @@ -746,7 +748,7 @@ check_and_wait_network_ready() local errmsg while true; do - errmsg=$(ssh -i $SSH_KEY_LOCATION -o BatchMode=yes $DUMP_TARGET mkdir -p $SAVE_PATH 2>&1) + errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1) retval=$? # ssh exits with the exit status of the remote command or with 255 if an error occurred @@ -759,7 +761,7 @@ check_and_wait_network_ready() # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa ddebug "$errmsg" - echo $errmsg | grep -q "Permission denied\|No such file or directory\|Host key verification failed" + echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed" if [[ $? -eq 0 ]]; then derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" return 1 @@ -808,16 +810,16 @@ propagate_ssh_key() dinfo "Using existing keys..." else dinfo "Generating new ssh keys... " - /usr/bin/ssh-keygen -t rsa -f $KEYFILE -N "" 2>&1 > /dev/null + /usr/bin/ssh-keygen -t rsa -f "$KEYFILE" -N "" 2>&1 > /dev/null dinfo "done." fi #now find the target ssh user and server to contact. - SSH_USER=$(echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1) - SSH_SERVER=$(echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/') + SSH_USER=$(echo "$DUMP_TARGET" | cut -d@ -f1) + SSH_SERVER=$(echo "$DUMP_TARGET" | sed -e's/\(.*@\)\(.*$\)/\2/') #now send the found key to the found server - ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER + ssh-copy-id -i "$KEYFILE" "$SSH_USER@$SSH_SERVER" RET=$? if [[ $RET == 0 ]]; then dinfo "$KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER" @@ -836,7 +838,7 @@ show_reserved_mem() mem=$(/dev/null 2>&1; then + if makedumpfile -R "$coredir/vmcore" < "$raw_target" >/dev/null 2>&1; then # dump found dinfo "Dump saved to $coredir/vmcore" # wipe makedumpfile header - dd if=/dev/zero of=$raw_target bs=1b count=1 2>/dev/null + dd if=/dev/zero of="$raw_target" bs=1b count=1 2>/dev/null else rm -rf "$coredir" fi @@ -904,7 +906,7 @@ local_fs_dump_target() _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) if [[ $? -eq 0 ]]; then - echo $_target|awk '{print $2}' + echo "$_target" | awk '{print $2}' fi } @@ -919,7 +921,7 @@ path_to_be_relabeled() _target=$(local_fs_dump_target) if [[ -n "$_target" ]]; then - _mnt=$(get_mntpoint_from_target $_target) + _mnt=$(get_mntpoint_from_target "$_target") if ! is_mounted "$_mnt"; then return fi @@ -930,9 +932,9 @@ path_to_be_relabeled() _path=$(get_save_path) # if $_path is masked by other mount, we will not relabel it. - _rmnt=$(df $_mnt/$_path 2>/dev/null | tail -1 | awk '{ print $NF }') + _rmnt=$(df "$_mnt/$_path" 2>/dev/null | tail -1 | awk '{ print $NF }') if [[ "$_rmnt" == "$_mnt" ]]; then - echo $_mnt/$_path + echo "$_mnt/$_path" fi } diff --git a/mkdumprd b/mkdumprd index 3101d3f..b5cc39e 100644 --- a/mkdumprd +++ b/mkdumprd @@ -60,9 +60,9 @@ add_dracut_sshkey() { to_mount() { local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev - _new_mntpoint=$(get_kdump_mntpoint_from_target $_target) - _fstype="${_fstype:-$(get_fs_type_from_target $_target)}" - _options="${_options:-$(get_mntopt_from_target $_target)}" + _new_mntpoint=$(get_kdump_mntpoint_from_target "$_target") + _fstype="${_fstype:-$(get_fs_type_from_target "$_target")}" + _options="${_options:-$(get_mntopt_from_target "$_target")}" _options="${_options:-defaults}" if [[ "$_fstype" == "nfs"* ]]; then @@ -72,8 +72,8 @@ to_mount() { _sed_cmd+='s/,clientaddr=[^,]*//;' else # for non-nfs _target converting to use udev persistent name - _pdev="$(kdump_get_persistent_dev $_target)" - if [[ -z "$_pdev" ]]; then + _pdev="$(kdump_get_persistent_dev "$_target")" + if [[ -z $_pdev ]]; then return 1 fi fi @@ -114,19 +114,19 @@ mkdir_save_path_ssh() { local _opt _dir _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) - ssh -qn "${_opt[@]}" $1 mkdir -p $SAVE_PATH 2>&1 > /dev/null + ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" 2>&1 > /dev/null _ret=$? if [[ $_ret -ne 0 ]]; then perror_exit "mkdir failed on $1:$SAVE_PATH" fi #check whether user has write permission on $1:$SAVE_PATH - _dir=$(ssh -qn "${_opt[@]}" $1 mktemp -dqp $SAVE_PATH 2>/dev/null) + _dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null) _ret=$? if [[ $_ret -ne 0 ]]; then perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" fi - ssh -qn "${_opt[@]}" $1 rmdir $_dir + ssh -qn "${_opt[@]}" "$1" rmdir "$_dir" return 0 } @@ -168,7 +168,7 @@ check_size() { perror_exit "Check dump target size failed" fi - if [[ $avail -lt $memtotal ]]; then + if [[ "$avail" -lt "$memtotal" ]]; then dwarn "Warning: There might not be enough space to save a vmcore." dwarn " The size of $2 should be greater than $memtotal kilo bytes." fi @@ -206,9 +206,9 @@ mount_failure() check_user_configured_target() { local _target=$1 _cfg_fs_type=$2 _mounted - local _mnt=$(get_mntpoint_from_target $_target) - local _opt=$(get_mntopt_from_target $_target) - local _fstype=$(get_fs_type_from_target $_target) + local _mnt=$(get_mntpoint_from_target "$_target") + local _opt=$(get_mntopt_from_target "$_target") + local _fstype=$(get_fs_type_from_target "$_target") if [[ -n "$_fstype" ]]; then # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf @@ -227,7 +227,7 @@ check_user_configured_target() if [[ -n "$_mnt" ]]; then if ! is_mounted "$_mnt"; then if [[ $_opt = *",noauto"* ]]; then - mount $_mnt + mount "$_mnt" [[ $? -ne 0 ]] && mount_failure "$_target" "$_mnt" "$_fstype" _mounted=$_mnt else @@ -236,8 +236,8 @@ check_user_configured_target() fi else _mnt=$MKDUMPRD_TMPMNT - mkdir -p $_mnt - mount $_target $_mnt -t $_fstype -o defaults + mkdir -p "$_mnt" + mount "$_target" "$_mnt" -t "$_fstype" -o defaults [[ $? -ne 0 ]] && mount_failure "$_target" "" "$_fstype" _mounted=$_mnt fi @@ -251,7 +251,7 @@ check_user_configured_target() # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway if [[ -n "$_mounted" ]]; then - umount -f -- $_mounted + umount -f -- "$_mounted" fi } @@ -276,13 +276,14 @@ verify_core_collector() { _params="$_params vmcore dumpfile" fi + # shellcheck disable=SC2086 if ! $_cmd --check-params $_params; then perror_exit "makedumpfile parameter check failed." fi } add_mount() { - local _mnt=$(to_mount $@) + local _mnt=$(to_mount "$@") if [[ $? -ne 0 ]]; then exit 1 @@ -299,15 +300,15 @@ handle_default_dump_target() is_user_configured_dump_target && return - check_save_path_fs $SAVE_PATH + check_save_path_fs "$SAVE_PATH" - _save_path=$(get_bind_mount_source $SAVE_PATH) - _target=$(get_target_from_path $_save_path) - _mntpoint=$(get_mntpoint_from_target $_target) + _save_path=$(get_bind_mount_source "$SAVE_PATH") + _target=$(get_target_from_path "$_save_path") + _mntpoint=$(get_mntpoint_from_target "$_target") SAVE_PATH=${_save_path##"$_mntpoint"} add_mount "$_target" - check_size fs $_target + check_size fs "$_target" } # $1: function name @@ -317,8 +318,8 @@ for_each_block_target() for dev in $(get_kdump_targets); do [[ -b "$dev" ]] || continue - majmin=$(get_maj_min $dev) - check_block_and_slaves $1 $majmin && return 1 + majmin=$(get_maj_min "$dev") + check_block_and_slaves "$1" "$majmin" && return 1 done return 0 @@ -328,14 +329,14 @@ for_each_block_target() #return false if unresettable. is_unresettable() { - local path="/sys/$(udevadm info --query=all --path=/sys/dev/block/$1 | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" + local path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" local resettable=1 if [[ -f "$path" ]] then resettable="$(<"$path")" [[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && { - local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}') + local device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') derror "Error: Can not save vmcore because device $device is unresettable" return 0 } @@ -387,7 +388,7 @@ fi keyfile=$(kdump_get_conf_val sshkey) if [[ -f "$keyfile" ]]; then # canonicalize the path - SSH_KEY_LOCATION=$(/usr/bin/readlink -m $keyfile) + SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$keyfile") fi while read -r config_opt config_val; @@ -403,21 +404,21 @@ do ;; raw) # checking raw disk writable - dd if=$config_val count=1 of=/dev/null > /dev/null 2>&1 || { + dd if="$config_val" count=1 of=/dev/null > /dev/null 2>&1 || { perror_exit "Bad raw disk $config_val" } - _praw=$(persistent_policy="by-id" kdump_get_persistent_dev $config_val) - if [[ -z "$_praw" ]]; then + _praw=$(persistent_policy="by-id" kdump_get_persistent_dev "$config_val") + if [[ -z $_praw ]]; then exit 1 fi add_dracut_arg "--device" "$_praw" - check_size raw $config_val + check_size raw "$config_val" ;; ssh) if strstr "$config_val" "@"; then - mkdir_save_path_ssh $config_val - check_size ssh $config_val + mkdir_save_path_ssh "$config_val" + check_size ssh "$config_val" add_dracut_sshkey "$SSH_KEY_LOCATION" else perror_exit "Bad ssh dump target $config_val" @@ -451,7 +452,7 @@ fi if ! is_fadump_capable; then # The 2nd rootfs mount stays behind the normal dump target mount, # so it doesn't affect the logic of check_dump_fs_modified(). - is_dump_to_rootfs && add_mount "$(to_dev_name $(get_root_fs_device))" + is_dump_to_rootfs && add_mount "$(to_dev_name "$(get_root_fs_device)")" add_dracut_arg "--no-hostonly-default-device" fi From a4648fc851be56d141fd43c8ade1a61c4069f47e Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 17:23:16 +0800 Subject: [PATCH 124/454] bash scripts: fix redundant exit code check As suggested by: https://github.com/koalaman/shellcheck/wiki/SC2181 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 41 ++++++--------- kdumpctl | 112 +++++++++++++---------------------------- mkdumprd | 40 ++++----------- 3 files changed, 61 insertions(+), 132 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 07a96e5..7c51e01 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -255,8 +255,7 @@ kdump_static_ip() { _gateway="[$_gateway]" else _prefix=$(cut -d'/' -f2 <<< "$_ipaddr") - _netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6_flag") - if [[ "$?" -ne 0 ]]; then + if ! _netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6_flag"); then derror "Failed to calculate netmask for $_ipaddr" exit 1 fi @@ -359,10 +358,7 @@ kdump_setup_bridge() { _dev=${_dev##*/} _kdumpdev=$_dev if kdump_is_bond "$_dev"; then - (kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") - if [[ $? != 0 ]]; then - exit 1 - fi + (kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") || exit 1 elif kdump_is_team "$_dev"; then kdump_setup_team "$_dev" elif kdump_is_vlan "$_dev"; then @@ -420,9 +416,7 @@ kdump_setup_team() { echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf" #Buggy version teamdctl outputs to stderr! #Try to use the latest version of teamd. - teamdctl "$_netdev" config dump > "${initdir}/tmp/$$-$_netdev.conf" - if [[ $? -ne 0 ]] - then + if ! teamdctl "$_netdev" config dump > "${initdir}/tmp/$$-$_netdev.conf"; then derror "teamdctl failed." exit 1 fi @@ -442,10 +436,7 @@ kdump_setup_vlan() { derror "Vlan over bridge is not supported!" exit 1 elif kdump_is_bond "$_phydev"; then - (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") - if [[ $? != 0 ]]; then - exit 1 - fi + (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") || exit 1 echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" else _kdumpdev="$(kdump_setup_ifname "$_phydev")" @@ -516,8 +507,8 @@ kdump_setup_znet() { kdump_get_ip_route() { - local _route=$(/sbin/ip -o route get to "$1" 2>&1) - if [[ $? != 0 ]]; then + local _route + if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then derror "Bad kdump network destination: $1" exit 1 fi @@ -561,8 +552,7 @@ kdump_install_net() { _znet_netdev=$(find_online_znet_device) if [[ -n "$_znet_netdev" ]]; then _nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev") - (kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet") - if [[ $? != 0 ]]; then + if ! (kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet"); then derror "Failed to set up znet" exit 1 fi @@ -592,10 +582,7 @@ kdump_install_net() { if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then - (kdump_setup_bond "$_netdev" "$_nm_show_cmd") - if [[ $? != 0 ]]; then - exit 1 - fi + (kdump_setup_bond "$_netdev" "$_nm_show_cmd") || exit 1 elif kdump_is_team "$_netdev"; then kdump_setup_team "$_netdev" elif kdump_is_vlan "$_netdev"; then @@ -837,8 +824,10 @@ kdump_setup_iscsi_device() { fi # Setup initator - initiator_str=$(kdump_get_iscsi_initiator) - [[ $? -ne "0" ]] && derror "Failed to get initiator name" && return 1 + if ! initiator_str=$(kdump_get_iscsi_initiator); then + derror "Failed to get initiator name" + return 1 + fi # If initiator details do not exist already, append. if ! grep -q "$initiator_str" "$netroot_conf"; then @@ -878,8 +867,7 @@ get_alias() { for ip in $ips do # in /etc/hosts, alias can come at the 2nd column - entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }') - if [[ $? -eq 0 ]]; then + if entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }'); then alias_set="$alias_set $entries" fi done @@ -1004,8 +992,7 @@ kdump_install_random_seed() { kdump_install_systemd_conf() { # Kdump turns out to require longer default systemd mount timeout # than 1st kernel(90s by default), we use default 300s for kdump. - grep -r "^[[:space:]]*DefaultTimeoutStartSec=" "${initdir}/etc/systemd/system.conf"* &>/dev/null - if [[ $? -ne 0 ]]; then + if ! grep -q -r "^[[:space:]]*DefaultTimeoutStartSec=" "${initdir}/etc/systemd/system.conf"*; then mkdir -p "${initdir}/etc/systemd/system.conf.d" echo "[Manager]" > "${initdir}/etc/systemd/system.conf.d/kdump.conf" echo "DefaultTimeoutStartSec=300s" >> "${initdir}/etc/systemd/system.conf.d/kdump.conf" diff --git a/kdumpctl b/kdumpctl index ed6dc3a..208818c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -37,8 +37,7 @@ fi . /lib/kdump/kdump-logger.sh #initiate the kdump logger -dlog_init -if [[ $? -ne 0 ]]; then +if ! dlog_init; then echo "failed to initiate the kdump logger." exit 1 fi @@ -47,8 +46,7 @@ single_instance_lock() { local rc timeout=5 - exec 9>/var/lock/kdump - if [[ $? -ne 0 ]]; then + if ! exec 9>/var/lock/kdump; then derror "Create file lock failed" exit 1 fi @@ -80,8 +78,7 @@ save_core() mkdir -p "$coredir" ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" - cp --sparse=always /proc/vmcore "$coredir/vmcore-incomplete" - if [[ $? == 0 ]]; then + if cp --sparse=always /proc/vmcore "$coredir/vmcore-incomplete"; then mv "$coredir/vmcore-incomplete" "$coredir/vmcore" dinfo "saved a vmcore to $coredir" else @@ -95,8 +92,7 @@ save_core() ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" >/dev/null 2>&1 ddebug "dumpoops -d $coredir/dmesg" - dumpoops -d "$coredir/dmesg" >/dev/null 2>&1 - if [[ $? == 0 ]]; then + if dumpoops -d "$coredir/dmesg" >/dev/null 2>&1; then dinfo "kernel oops has been collected by abrt tool" fi fi @@ -121,8 +117,7 @@ check_earlykdump_is_enabled() rebuild_kdump_initrd() { ddebug "rebuild kdump initrd: $MKDUMPRD $TARGET_INITRD $KDUMP_KERNELVER" - $MKDUMPRD "$TARGET_INITRD" "$KDUMP_KERNELVER" - if [[ $? != 0 ]]; then + if ! $MKDUMPRD "$TARGET_INITRD" "$KDUMP_KERNELVER"; then derror "mkdumprd: failed to make kdump initrd" return 1 fi @@ -184,8 +179,7 @@ backup_default_initrd() dinfo "Backing up $DEFAULT_INITRD before rebuild." # save checksum to verify before restoring sha1sum "$DEFAULT_INITRD" > "$INITRD_CHECKSUM_LOCATION" - cp "$DEFAULT_INITRD" "$DEFAULT_INITRD_BAK" - if [[ $? -ne 0 ]]; then + if ! cp "$DEFAULT_INITRD" "$DEFAULT_INITRD_BAK"; then dwarn "WARNING: failed to backup $DEFAULT_INITRD." rm -f "$DEFAULT_INITRD_BAK" fi @@ -210,8 +204,7 @@ restore_default_initrd() dwarn "WARNING: checksum mismatch! Can't restore original initrd.." else rm -f $INITRD_CHECKSUM_LOCATION - mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD" - if [[ $? -eq 0 ]]; then + if mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD"; then derror "Restoring original initrd as fadump mode is disabled." sync fi @@ -308,8 +301,7 @@ get_pcs_cluster_modified_files() setup_initrd() { - prepare_kdump_bootinfo - if [[ $? -ne 0 ]]; then + if ! prepare_kdump_bootinfo; then derror "failed to prepare for kdump bootinfo." return 1 fi @@ -372,8 +364,7 @@ check_files_modified() files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" fi for _module in $EXTRA_MODULES; do - _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)" - if [[ $? -eq 0 ]]; then + if _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)"; then files="$files $_module_file" for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2>/dev/null)" @@ -389,8 +380,7 @@ check_files_modified() # HOOKS is mandatory and need to check the modification time files="$files $HOOKS" - check_exist "$files" && check_executable "$EXTRA_BINS" - [[ $? -ne 0 ]] && return 2 + check_exist "$files" && check_executable "$EXTRA_BINS" || return 2 for file in $files; do if [[ -e "$file" ]]; then @@ -455,7 +445,7 @@ check_drivers_modified() # Skip deprecated/invalid driver name or built-in module _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null) _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2>/dev/null) - if [[ $? -ne 0 ]] || [[ -z "$_module_name" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then + if [[ -z "$_module_name" ]] || [[ -z "$_module_filename" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then continue fi if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then @@ -505,8 +495,7 @@ check_fs_modified() # if --mount argument present then match old and new target, mount # point and file system. If any of them mismatches then rebuild - echo "$_dracut_args" | grep -q "\-\-mount" - if [[ $? -eq 0 ]];then + if echo "$_dracut_args" | grep -q "\-\-mount"; then # shellcheck disable=SC2046 set -- $(echo "$_dracut_args" | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) _old_dev=$1 @@ -558,11 +547,7 @@ check_rebuild() local force_rebuild force_no_rebuild local ret system_modified="0" - setup_initrd - - if [[ $? -ne 0 ]]; then - return 1 - fi + setup_initrd || return 1 force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) force_no_rebuild=${force_no_rebuild:-0} @@ -761,8 +746,7 @@ check_and_wait_network_ready() # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa ddebug "$errmsg" - echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed" - if [[ $? -eq 0 ]]; then + if echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed"; then derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" return 1 fi @@ -788,16 +772,11 @@ check_and_wait_network_ready() check_ssh_target() { check_and_wait_network_ready - if [[ $? -ne 0 ]]; then - return 1 - fi - return 0 } propagate_ssh_key() { - check_ssh_config - if [[ $? -ne 0 ]]; then + if ! check_ssh_config; then derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate" exit 1 fi @@ -904,8 +883,7 @@ local_fs_dump_target() { local _target - _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf) - if [[ $? -eq 0 ]]; then + if _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf); then echo "$_target" | awk '{print $2}' fi } @@ -967,8 +945,7 @@ check_fence_kdump_config() return 1 fi # node can be ipaddr - echo "$ipaddrs " | grep -q "$node " - if [[ $? -eq 0 ]]; then + if echo "$ipaddrs " | grep -q "$node "; then derror "Option fence_kdump_nodes cannot contain $node" return 1 fi @@ -1062,14 +1039,12 @@ check_final_action_config() start() { - check_dump_feasibility - if [[ $? -ne 0 ]]; then + if ! check_dump_feasibility; then derror "Starting kdump: [FAILED]" return 1 fi - check_config - if [[ $? -ne 0 ]]; then + if ! check_config; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1078,14 +1053,12 @@ start() selinux_relabel fi - save_raw - if [[ $? -ne 0 ]]; then + if ! save_raw; then derror "Starting kdump: [FAILED]" return 1 fi - check_current_status - if [[ $? == 0 ]]; then + if check_current_status; then dwarn "Kdump already running: [WARNING]" return 0 fi @@ -1097,14 +1070,12 @@ start() fi fi - check_rebuild - if [[ $? != 0 ]]; then + if ! check_rebuild; then derror "Starting kdump: [FAILED]" return 1 fi - start_dump - if [[ $? != 0 ]]; then + if ! start_dump; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1114,8 +1085,7 @@ start() reload() { - check_current_status - if [[ $? -ne 0 ]]; then + if ! check_current_status; then dwarn "Kdump was not running: [WARNING]" fi @@ -1123,24 +1093,20 @@ reload() reload_fadump return $? else - stop_kdump - fi - - if [[ $? -ne 0 ]]; then - derror "Stopping kdump: [FAILED]" - return 1 + if ! stop_kdump; then + derror "Stopping kdump: [FAILED]" + return 1 + fi fi dinfo "Stopping kdump: [OK]" - setup_initrd - if [[ $? -ne 0 ]]; then + if ! setup_initrd; then derror "Starting kdump: [FAILED]" return 1 fi - start_dump - if [[ $? -ne 0 ]]; then + if ! start_dump; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1168,6 +1134,7 @@ stop_kdump() $KEXEC -p -u fi + # shellcheck disable=SC2181 if [[ $? != 0 ]]; then derror "kexec: failed to unload kdump kernel" return 1 @@ -1179,16 +1146,14 @@ stop_kdump() reload_fadump() { - echo 1 > $FADUMP_REGISTER_SYS_NODE - if [[ $? == 0 ]]; then + if echo 1 > $FADUMP_REGISTER_SYS_NODE; then dinfo "fadump: re-registered successfully" return 0 else # FADump could fail on older kernel where re-register # support is not enabled. Try stop/start from userspace # to handle such scenario. - stop_fadump - if [[ $? == 0 ]]; then + if stop_fadump; then start_fadump return $? fi @@ -1205,6 +1170,7 @@ stop() stop_kdump fi + # shellcheck disable=SC2181 if [[ $? != 0 ]]; then derror "Stopping kdump: [FAILED]" return 1 @@ -1215,10 +1181,7 @@ stop() } rebuild() { - check_config - if [[ $? -ne 0 ]]; then - return 1 - fi + check_config || return 1 if check_ssh_config; then if ! check_ssh_target; then @@ -1226,10 +1189,7 @@ rebuild() { fi fi - setup_initrd - if [[ $? -ne 0 ]]; then - return 1 - fi + setup_initrd || return 1 dinfo "Rebuilding $TARGET_INITRD" rebuild_initrd diff --git a/mkdumprd b/mkdumprd index b5cc39e..b75bbdd 100644 --- a/mkdumprd +++ b/mkdumprd @@ -17,8 +17,7 @@ fi export IN_KDUMP=1 #initiate the kdump logger -dlog_init -if [[ $? -ne 0 ]]; then +if ! dlog_init; then echo "failed to initiate the kdump logger." exit 1 fi @@ -114,18 +113,12 @@ mkdir_save_path_ssh() { local _opt _dir _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) - ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" 2>&1 > /dev/null - _ret=$? - if [[ $_ret -ne 0 ]]; then + ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" &>/dev/null || \ perror_exit "mkdir failed on $1:$SAVE_PATH" - fi - #check whether user has write permission on $1:$SAVE_PATH - _dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null) - _ret=$? - if [[ $_ret -ne 0 ]]; then + # check whether user has write permission on $1:$SAVE_PATH + _dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null) || \ perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" - fi ssh -qn "${_opt[@]}" "$1" rmdir "$_dir" return 0 @@ -162,11 +155,7 @@ check_size() { ;; *) return - esac - - if [[ $? -ne 0 ]]; then - perror_exit "Check dump target size failed" - fi + esac || perror_exit "Check dump target size failed" if [[ "$avail" -lt "$memtotal" ]]; then dwarn "Warning: There might not be enough space to save a vmcore." @@ -227,8 +216,7 @@ check_user_configured_target() if [[ -n "$_mnt" ]]; then if ! is_mounted "$_mnt"; then if [[ $_opt = *",noauto"* ]]; then - mount "$_mnt" - [[ $? -ne 0 ]] && mount_failure "$_target" "$_mnt" "$_fstype" + mount "$_mnt" || mount_failure "$_target" "$_mnt" "$_fstype" _mounted=$_mnt else perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" @@ -237,8 +225,7 @@ check_user_configured_target() else _mnt=$MKDUMPRD_TMPMNT mkdir -p "$_mnt" - mount "$_target" "$_mnt" -t "$_fstype" -o defaults - [[ $? -ne 0 ]] && mount_failure "$_target" "" "$_fstype" + mount "$_target" "$_mnt" -t "$_fstype" -o defaults || mount_failure "$_target" "" "$_fstype" _mounted=$_mnt fi @@ -283,11 +270,9 @@ verify_core_collector() { } add_mount() { - local _mnt=$(to_mount "$@") + local _mnt - if [[ $? -ne 0 ]]; then - exit 1 - fi + _mnt=$(to_mount "$@") || exit 1 add_dracut_mount "$_mnt" } @@ -349,7 +334,7 @@ is_unresettable() #return true if resettable check_resettable() { - local _ret _target _override_resettable + local _target _override_resettable _override_resettable=$(kdump_get_conf_val override_resettable) OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE} @@ -357,10 +342,7 @@ check_resettable() perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid" fi - for_each_block_target is_unresettable - _ret=$? - - [[ $_ret -eq 0 ]] && return + for_each_block_target is_unresettable && return return 1 } From 4f75e16700874b2e934fb3b9b85522cf7f36bd04 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 18 Aug 2021 02:04:45 +0800 Subject: [PATCH 125/454] bash scripts: declare and assign separately Declare and assign separately to avoid masking return values: https://github.com/koalaman/shellcheck/wiki/SC2155 Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 22 +++++++++++++++------- kdumpctl | 17 ++++++++++++----- mkdumprd | 21 +++++++++++---------- mkfadumprd | 2 +- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 7c51e01..e9ec894 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -321,7 +321,8 @@ kdump_get_mac_addr() { #Bonding or team master modifies the mac address #of its slaves, we should use perm address kdump_get_perm_addr() { - local addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //') + local addr + addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //') if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]] then derror "Can't get the permanent address of $1" @@ -427,10 +428,13 @@ kdump_setup_team() { kdump_setup_vlan() { local _netdev=$1 - local _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" - local _netmac="$(kdump_get_mac_addr "$_phydev")" + local _phydev + local _netmac local _kdumpdev + _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" + _netmac="$(kdump_get_mac_addr "$_phydev")" + #Just support vlan over bond and team if kdump_is_bridge "$_phydev"; then derror "Vlan over bridge is not supported!" @@ -522,7 +526,8 @@ kdump_get_ip_route_field() kdump_get_remote_ip() { - local _remote=$(get_remote_host "$1") _remote_temp + local _remote _remote_temp + _remote=$(get_remote_host "$1") if is_hostname "$_remote"; then _remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1) if [[ -z "$_remote_temp" ]]; then @@ -876,11 +881,14 @@ get_alias() { } is_localhost() { - local hostnames=$(hostname -A) - local shortnames=$(hostname -A -s) - local aliasname=$(get_alias) + local hostnames + local shortnames + local aliasname local nodename=$1 + hostnames=$(hostname -A) + shortnames=$(hostname -A -s) + aliasname=$(get_alias) hostnames="$hostnames $shortnames $aliasname" for name in ${hostnames}; do diff --git a/kdumpctl b/kdumpctl index 208818c..d11c3c1 100755 --- a/kdumpctl +++ b/kdumpctl @@ -690,6 +690,8 @@ load_kdump() check_ssh_config() { + local SSH_TARGET + while read -r config_opt config_val; do case "$config_opt" in sshkey) @@ -713,7 +715,7 @@ check_ssh_config() done <<< "$(kdump_read_conf)" #make sure they've configured kdump.conf for ssh dumps - local SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p') + SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p') if [[ -z "$SSH_TARGET" ]]; then return 1 fi @@ -725,13 +727,14 @@ check_ssh_config() # by the return val of 'ssh' check_and_wait_network_ready() { - local start_time=$(date +%s) + local start_time local warn_once=1 local cur local diff local retval local errmsg + start_time=$(date +%s) while true; do errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1) retval=$? @@ -935,9 +938,13 @@ selinux_relabel() check_fence_kdump_config() { - local hostname=$(hostname) - local ipaddrs=$(hostname -I) - local nodes=$(kdump_get_conf_val "fence_kdump_nodes") + local hostname + local ipaddrs + local nodes + + hostname=$(hostname) + ipaddrs=$(hostname -I) + nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in $nodes; do if [[ "$node" = "$hostname" ]]; then diff --git a/mkdumprd b/mkdumprd index b75bbdd..a027e6a 100644 --- a/mkdumprd +++ b/mkdumprd @@ -29,9 +29,9 @@ OVERRIDE_RESETTABLE=0 extra_modules="" dracut_args=( --add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump" ) -readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" +MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." -readonly MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target" +MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target" trap ' ret=$?; @@ -195,9 +195,11 @@ mount_failure() check_user_configured_target() { local _target=$1 _cfg_fs_type=$2 _mounted - local _mnt=$(get_mntpoint_from_target "$_target") - local _opt=$(get_mntopt_from_target "$_target") - local _fstype=$(get_fs_type_from_target "$_target") + local _mnt _opt _fstype + + _mnt=$(get_mntpoint_from_target "$_target") + _opt=$(get_mntopt_from_target "$_target") + _fstype=$(get_fs_type_from_target "$_target") if [[ -n "$_fstype" ]]; then # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf @@ -314,14 +316,13 @@ for_each_block_target() #return false if unresettable. is_unresettable() { - local path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" - local resettable=1 + local path device resettable=1 - if [[ -f "$path" ]] - then + path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" + if [[ -f "$path" ]]; then resettable="$(<"$path")" [[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && { - local device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') + device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') derror "Error: Can not save vmcore because device $device is unresettable" return 0 } diff --git a/mkfadumprd b/mkfadumprd index ca9f362..5c96ee7 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -17,7 +17,7 @@ if ! dlog_init; then exit 1 fi -readonly MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)" +MKFADUMPRD_TMPDIR="$(mktemp -d -t mkfadumprd.XXXXXX)" [ -d "$MKFADUMPRD_TMPDIR" ] || perror_exit "mkfadumprd: mktemp -d -t mkfadumprd.XXXXXX failed." trap ' ret=$?; From 0e4b66b1ab4d90bea8f3021a46660f5a253eb110 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 14 Sep 2021 02:25:40 +0800 Subject: [PATCH 126/454] bash scripts: reformat with shfmt This is a batch update done with: shfmt -s -w mkfadumprd mkdumprd kdumpctl *-module-setup.sh Clean up code style and reduce code base size, no behaviour change. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-early-kdump-module-setup.sh | 11 +- dracut-module-setup.sh | 318 +++++++++--------- kdumpctl | 274 +++++++-------- mkdumprd | 518 +++++++++++++++-------------- mkfadumprd | 8 +- 5 files changed, 570 insertions(+), 559 deletions(-) diff --git a/dracut-early-kdump-module-setup.sh b/dracut-early-kdump-module-setup.sh index 83e067c..0e46823 100755 --- a/dracut-early-kdump-module-setup.sh +++ b/dracut-early-kdump-module-setup.sh @@ -6,9 +6,8 @@ KDUMP_KERNEL="" KDUMP_INITRD="" check() { - if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]]\ - || [[ -n "${IN_KDUMP}" ]] - then + if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]] \ + || [[ -n ${IN_KDUMP} ]]; then return 1 fi return 255 @@ -25,7 +24,7 @@ prepare_kernel_initrd() { prepare_kdump_bootinfo # $kernel is a variable from dracut - if [[ "$KDUMP_KERNELVER" != "$kernel" ]]; then + if [[ $KDUMP_KERNELVER != "$kernel" ]]; then dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \ "but the initramfs is generated for kernel version '$kernel'" fi @@ -33,12 +32,12 @@ prepare_kernel_initrd() { install() { prepare_kernel_initrd - if [[ ! -f "$KDUMP_KERNEL" ]]; then + if [[ ! -f $KDUMP_KERNEL ]]; then derror "Could not find required kernel for earlykdump," \ "earlykdump will not work!" return 1 fi - if [[ ! -f "$KDUMP_INITRD" ]]; then + if [[ ! -f $KDUMP_INITRD ]]; then derror "Could not find required kdump initramfs for earlykdump," \ "please ensure kdump initramfs is generated first," \ "earlykdump will not work!" diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index e9ec894..8bbf0cf 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -11,8 +11,7 @@ kdump_module_init() { check() { [[ $debug ]] && set -x #kdumpctl sets this explicitly - if [[ -z "$IN_KDUMP" ]] || [[ ! -f /etc/kdump.conf ]] - then + if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then return 1 fi return 0 @@ -41,11 +40,11 @@ depends() { _dep="$_dep ssh-client" fi - if [[ "$(uname -m)" = "s390x" ]]; then + if [[ "$(uname -m)" == "s390x" ]]; then _dep="$_dep znet" fi - if [[ -n "$( ls -A /sys/class/drm 2>/dev/null )" ]] || [[ -d /sys/module/hyperv_fb ]]; then + if [[ -n "$(ls -A /sys/class/drm 2> /dev/null)" ]] || [[ -d /sys/module/hyperv_fb ]]; then add_opt_module drm fi @@ -57,19 +56,19 @@ depends() { } kdump_is_bridge() { - [[ -d /sys/class/net/"$1"/bridge ]] + [[ -d /sys/class/net/"$1"/bridge ]] } kdump_is_bond() { - [[ -d /sys/class/net/"$1"/bonding ]] + [[ -d /sys/class/net/"$1"/bonding ]] } kdump_is_team() { - [[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null + [[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null } kdump_is_vlan() { - [[ -f /proc/net/vlan/"$1" ]] + [[ -f /proc/net/vlan/"$1" ]] } # $1: netdev name @@ -78,7 +77,7 @@ source_ifcfg_file() { dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." ifcfg_file=$(get_ifcfg_filename "$1") - if [[ -f "${ifcfg_file}" ]]; then + if [[ -f ${ifcfg_file} ]]; then . "${ifcfg_file}" else dwarning "The ifcfg file of $1 is not found!" @@ -94,28 +93,26 @@ kdump_setup_dns() { _tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS") # shellcheck disable=SC2206 - array=( ${_tmp//|/ } ) + array=(${_tmp//|/ }) if [[ ${array[*]} ]]; then - for _dns in "${array[@]}" - do + for _dns in "${array[@]}"; do echo "nameserver=$_dns" >> "$_dnsfile" done else dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script" source_ifcfg_file "$_netdev" - [[ -n "$DNS1" ]] && echo "nameserver=$DNS1" > "$_dnsfile" - [[ -n "$DNS2" ]] && echo "nameserver=$DNS2" >> "$_dnsfile" + [[ -n $DNS1 ]] && echo "nameserver=$DNS1" > "$_dnsfile" + [[ -n $DNS2 ]] && echo "nameserver=$DNS2" >> "$_dnsfile" fi - while read -r content; - do + while read -r content; do _nameserver=$(echo "$content" | grep ^nameserver) - [[ -z "$_nameserver" ]] && continue + [[ -z $_nameserver ]] && continue _dns=$(echo "$_nameserver" | awk '{print $2}') - [[ -z "$_dns" ]] && continue + [[ -z $_dns ]] && continue - if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile" ; then + if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile"; then echo "nameserver=$_dns" >> "$_dnsfile" fi done < "/etc/resolv.conf" @@ -130,7 +127,7 @@ repeatedly_join_str() { local _separator="$3" local i _res - if [[ "$_count" -le 0 ]]; then + if [[ $_count -le 0 ]]; then echo -n "" return fi @@ -139,7 +136,7 @@ repeatedly_join_str() { _res="$_str" ((_count--)) - while [[ "$i" -lt "$_count" ]]; do + while [[ $i -lt $_count ]]; do ((i++)) _res="${_res}${_separator}${_str}" done @@ -160,14 +157,14 @@ cal_netmask_by_prefix() { local _count _res _octets_per_group _octets_total _seperator _total_groups local _max_group_value _max_group_value_repr _bits_per_group _tmp _zero_bits - if [[ "$_ipv6_flag" == "-6" ]]; then + if [[ $_ipv6_flag == "-6" ]]; then _ipv6=1 else _ipv6=0 fi - if [[ "$_prefix" -lt 0 || "$_prefix" -gt 128 ]] || \ - ( ((!_ipv6)) && [[ "$_prefix" -gt 32 ]] ); then + if [[ $_prefix -lt 0 || $_prefix -gt 128 ]] \ + || ( ((!_ipv6)) && [[ $_prefix -gt 32 ]]); then derror "Bad prefix:$_prefix for calculating netmask" exit 1 fi @@ -182,7 +179,7 @@ cal_netmask_by_prefix() { _seperator="." fi - _total_groups=$((_octets_total/_octets_per_group)) + _total_groups=$((_octets_total / _octets_per_group)) _bits_per_group=$((_octets_per_group * _bits_per_octet)) _max_group_value=$(((1 << _bits_per_group) - 1)) @@ -192,39 +189,39 @@ cal_netmask_by_prefix() { _max_group_value_repr="$_max_group_value" fi - _count=$((_prefix/_octets_per_group/_bits_per_octet)) + _count=$((_prefix / _octets_per_group / _bits_per_octet)) _first_part=$(repeatedly_join_str "$_count" "$_max_group_value_repr" "$_seperator") _res="$_first_part" - _tmp=$((_octets_total*_bits_per_octet-_prefix)) + _tmp=$((_octets_total * _bits_per_octet - _prefix)) _zero_bits=$((_tmp % _bits_per_group)) - if [[ "$_zero_bits" -ne 0 ]]; then + if [[ $_zero_bits -ne 0 ]]; then _second_part=$((_max_group_value >> _zero_bits << _zero_bits)) if ((_ipv6)); then _second_part=$(printf "%x" $_second_part) fi ((_count++)) - if [[ -z "$_first_part" ]]; then + if [[ -z $_first_part ]]; then _res="$_second_part" else _res="${_first_part}${_seperator}${_second_part}" fi fi - _count=$((_total_groups-_count)) - if [[ "$_count" -eq 0 ]]; then + _count=$((_total_groups - _count)) + if [[ $_count -eq 0 ]]; then echo -n "$_res" return fi - if ((_ipv6)) && [[ "$_count" -gt 1 ]] ; then + if ((_ipv6)) && [[ $_count -gt 1 ]]; then # use condensed notion for IPv6 _third_part=":" else _third_part=$(repeatedly_join_str "$_count" "0" "$_seperator") fi - if [[ -z "$_res" ]] && ((!_ipv6)) ; then + if [[ -z $_res ]] && ((!_ipv6)); then echo -n "${_third_part}" else echo -n "${_res}${_seperator}${_third_part}" @@ -244,11 +241,11 @@ kdump_static_ip() { _ipv6_flag="-6" fi - if [[ -n "$_ipaddr" ]]; then - _gateway=$(ip $_ipv6_flag route list dev "$_netdev" | \ - awk '/^default /{print $3}' | head -n 1) + if [[ -n $_ipaddr ]]; then + _gateway=$(ip $_ipv6_flag route list dev "$_netdev" \ + | awk '/^default /{print $3}' | head -n 1) - if [[ "x" != "x"$_ipv6_flag ]]; then + if [[ "x" != "x"$_ipv6_flag ]]; then # _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/" _netmask=${_ipaddr#*\/} _srcaddr="[$_srcaddr]" @@ -263,17 +260,17 @@ kdump_static_ip() { echo -n "${_srcaddr}::${_gateway}:${_netmask}::" fi - /sbin/ip $_ipv6_flag route show | grep -v default |\ - grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\ - while read -r _route; do - _target=$(echo "$_route" | awk '{print $1}') - _nexthop=$(echo "$_route" | awk '{print $3}') - if [[ "x" != "x"$_ipv6_flag ]]; then - _target="[$_target]" - _nexthop="[$_nexthop]" - fi - echo "rd.route=$_target:$_nexthop:$kdumpnic" - done >> "${initdir}/etc/cmdline.d/45route-static.conf" + /sbin/ip $_ipv6_flag route show | grep -v default \ + | grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" \ + | while read -r _route; do + _target=$(echo "$_route" | awk '{print $1}') + _nexthop=$(echo "$_route" | awk '{print $3}') + if [[ "x" != "x"$_ipv6_flag ]]; then + _target="[$_target]" + _nexthop="[$_nexthop]" + fi + echo "rd.route=$_target:$_nexthop:$kdumpnic" + done >> "${initdir}/etc/cmdline.d/45route-static.conf" kdump_handle_mulitpath_route "$_netdev" "$_srcaddr" "$kdumpnic" } @@ -287,28 +284,28 @@ kdump_handle_mulitpath_route() { fi while IFS="" read -r _route; do - if [[ "$_route" =~ [[:space:]]+nexthop ]]; then + if [[ $_route =~ [[:space:]]+nexthop ]]; then _route=${_route##[[:space:]]} # Parse multipath route, using previous _target - [[ "$_target" == 'default' ]] && continue - [[ "$_route" =~ .*via.*\ $_netdev ]] || continue + [[ $_target == 'default' ]] && continue + [[ $_route =~ .*via.*\ $_netdev ]] || continue _weight=$(echo "$_route" | cut -d ' ' -f7) - if [[ "$_weight" -gt "$_max_weight" ]]; then + if [[ $_weight -gt $_max_weight ]]; then _nexthop=$(echo "$_route" | cut -d ' ' -f3) _max_weight=$_weight - if [[ "x" != "x"$_ipv6_flag ]]; then + if [[ "x" != "x"$_ipv6_flag ]]; then _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" else _rule="rd.route=$_target:$_nexthop:$kdumpnic" fi fi else - [[ -n "$_rule" ]] && echo "$_rule" + [[ -n $_rule ]] && echo "$_rule" _target=$(echo "$_route" | cut -d ' ' -f1) _rule="" _max_weight=0 _weight=0 fi - done >> "${initdir}/etc/cmdline.d/45route-static.conf"\ + done >> "${initdir}/etc/cmdline.d/45route-static.conf" \ <<< "$(/sbin/ip $_ipv6_flag route show)" [[ -n $_rule ]] && echo "$_rule" >> "${initdir}/etc/cmdline.d/45route-static.conf" @@ -323,8 +320,7 @@ kdump_get_mac_addr() { kdump_get_perm_addr() { local addr addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //') - if [[ -z "$addr" ]] || [[ "$addr" = "00:00:00:00:00:00" ]] - then + if [[ -z $addr ]] || [[ $addr == "00:00:00:00:00:00" ]]; then derror "Can't get the permanent address of $1" else echo "$addr" @@ -391,13 +387,13 @@ kdump_setup_bond() { _bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options") - if [[ -z "$_bondoptions" ]]; then + if [[ -z $_bondoptions ]]; then dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." source_ifcfg_file "$_netdev" _bondoptions="$(echo "$BONDING_OPTS" | xargs echo | tr " " ",")" fi - if [[ -z "$_bondoptions" ]]; then + if [[ -z $_bondoptions ]]; then derror "Get empty bond options" exit 1 fi @@ -453,30 +449,27 @@ kdump_setup_vlan() { # code reaped from the list_configured function of # https://github.com/hreinecke/s390-tools/blob/master/zconf/znetconf find_online_znet_device() { - local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" - local NETWORK_DEVICES d ifname ONLINE + local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" + local NETWORK_DEVICES d ifname ONLINE - [[ ! -d "$CCWGROUPBUS_DEVICEDIR" ]] && return - NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) - for d in $NETWORK_DEVICES - do - [[ ! -f "$d/online" ]] && continue - read -r ONLINE < "$d/online" - if [[ $ONLINE -ne 1 ]]; then - continue - fi - # determine interface name, if there (only for qeth and if - # device is online) - if [[ -f $d/if_name ]] - then - read -r ifname < "$d/if_name" - elif [[ -d $d/net ]] - then - ifname=$(ls "$d/net/") - fi - [[ -n "$ifname" ]] && break - done - echo -n "$ifname" + [[ ! -d $CCWGROUPBUS_DEVICEDIR ]] && return + NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) + for d in $NETWORK_DEVICES; do + [[ ! -f "$d/online" ]] && continue + read -r ONLINE < "$d/online" + if [[ $ONLINE -ne 1 ]]; then + continue + fi + # determine interface name, if there (only for qeth and if + # device is online) + if [[ -f $d/if_name ]]; then + read -r ifname < "$d/if_name" + elif [[ -d $d/net ]]; then + ifname=$(ls "$d/net/") + fi + [[ -n $ifname ]] && break + done + echo -n "$ifname" } # setup s390 znet cmdline @@ -494,7 +487,7 @@ kdump_setup_znet() { SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels") _options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options") - if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then + if [[ -z $NETTYPE || -z $SUBCHANNELS || -z $_options ]]; then dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script." source_ifcfg_file "$_netdev" for i in $OPTIONS; do @@ -502,15 +495,14 @@ kdump_setup_znet() { done fi - if [[ -z "$NETTYPE" || -z "$SUBCHANNELS" || -z "$_options" ]]; then + if [[ -z $NETTYPE || -z $SUBCHANNELS || -z $_options ]]; then exit 1 fi echo "rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS}" > "${initdir}/etc/cmdline.d/30znet.conf" } -kdump_get_ip_route() -{ +kdump_get_ip_route() { local _route if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then derror "Bad kdump network destination: $1" @@ -519,18 +511,16 @@ kdump_get_ip_route() echo "$_route" } -kdump_get_ip_route_field() -{ +kdump_get_ip_route_field() { echo "$1" | sed -n -e "s/^.*\<$2\>\s\+\(\S\+\).*$/\1/p" } -kdump_get_remote_ip() -{ +kdump_get_remote_ip() { local _remote _remote_temp _remote=$(get_remote_host "$1") if is_hostname "$_remote"; then _remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1) - if [[ -z "$_remote_temp" ]]; then + if [[ -z $_remote_temp ]]; then _remote_temp=$(getent ahosts "$_remote" | head -n 1) fi _remote=$(echo "$_remote_temp" | awk '{print $1}') @@ -555,7 +545,7 @@ kdump_install_net() { kdumpnic=$(kdump_setup_ifname "$_netdev") _znet_netdev=$(find_online_znet_device) - if [[ -n "$_znet_netdev" ]]; then + if [[ -n $_znet_netdev ]]; then _nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev") if ! (kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet"); then derror "Failed to set up znet" @@ -564,7 +554,7 @@ kdump_install_net() { fi _static=$(kdump_static_ip "$_netdev" "$_srcaddr" "$kdumpnic") - if [[ -n "$_static" ]]; then + if [[ -n $_static ]]; then _proto=none elif is_ipv6_address "$_srcaddr"; then _proto=auto6 @@ -579,8 +569,8 @@ kdump_install_net() { # so we have to avoid adding duplicates # We should also check /proc/cmdline for existing ip=xx arg. # For example, iscsi boot will specify ip=xxx arg in cmdline. - if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" &&\ - ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then + if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" \ + && ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then echo "$_ip_opts" >> "$_ip_conf" fi @@ -611,8 +601,8 @@ kdump_install_net() { # the default gate way for network dump, eth1 in the fence kdump path will # call kdump_install_net again and we don't want eth1 to be the default # gateway. - if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] && - [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then + if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] \ + && [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then echo "kdumpnic=$kdumpnic" > "${initdir}/etc/cmdline.d/60kdumpnic.conf" echo "bootdev=$kdumpnic" > "${initdir}/etc/cmdline.d/70bootdev.conf" fi @@ -622,17 +612,17 @@ kdump_install_net() { kdump_install_pre_post_conf() { if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do - if [[ -x "$file" ]]; then + if [[ -x $file ]]; then dracut_install "$file" elif [[ $file != "/etc/kdump/pre.d/*" ]]; then - echo "$file is not executable" + echo "$file is not executable" fi done fi if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do - if [[ -x "$file" ]]; then + if [[ -x $file ]]; then dracut_install "$file" elif [[ $file != "/etc/kdump/post.d/*" ]]; then echo "$file is not executable" @@ -641,8 +631,7 @@ kdump_install_pre_post_conf() { fi } -default_dump_target_install_conf() -{ +default_dump_target_install_conf() { local _target _fstype local _mntpoint _save_path @@ -663,7 +652,7 @@ default_dump_target_install_conf() echo "$_fstype $_target" >> "${initdir}/tmp/$$-kdump.conf" # don't touch the path under root mount - if [[ "$_mntpoint" != "/" ]]; then + if [[ $_mntpoint != "/" ]]; then _save_path=${_save_path##"$_mntpoint"} fi @@ -678,32 +667,31 @@ kdump_install_conf() { kdump_read_conf > "${initdir}/tmp/$$-kdump.conf" - while read -r _opt _val; - do + while read -r _opt _val; do # remove inline comments after the end of a directive. case "$_opt" in - raw) - _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val") - sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" - ;; - ext[234]|xfs|btrfs|minix) - _pdev=$(kdump_get_persistent_dev "$_val") - sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" - ;; - ssh|nfs) - kdump_install_net "$_val" - ;; - dracut_args) - if [[ $(get_dracut_args_fstype "$_val") = nfs* ]] ; then - kdump_install_net "$(get_dracut_args_target "$_val")" - fi - ;; - kdump_pre|kdump_post|extra_bins) - dracut_install "$_val" - ;; - core_collector) - dracut_install "${_val%%[[:blank:]]*}" - ;; + raw) + _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val") + sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" + ;; + ext[234] | xfs | btrfs | minix) + _pdev=$(kdump_get_persistent_dev "$_val") + sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" + ;; + ssh | nfs) + kdump_install_net "$_val" + ;; + dracut_args) + if [[ $(get_dracut_args_fstype "$_val") == nfs* ]]; then + kdump_install_net "$(get_dracut_args_target "$_val")" + fi + ;; + kdump_pre | kdump_post | extra_bins) + dracut_install "$_val" + ;; + core_collector) + dracut_install "${_val%%[[:blank:]]*}" + ;; esac done <<< "$(kdump_read_conf)" @@ -711,7 +699,7 @@ kdump_install_conf() { default_dump_target_install_conf - kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf" + kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf" inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf" rm -f "${initdir}/tmp/$$-kdump.conf" } @@ -744,16 +732,17 @@ kdump_get_iscsi_initiator() { local _initiator local initiator_conf="/etc/iscsi/initiatorname.iscsi" - [[ -f "$initiator_conf" ]] || return 1 + [[ -f $initiator_conf ]] || return 1 while read -r _initiator; do - [[ -z "${_initiator%%#*}" ]] && continue # Skip comment lines + [[ -z ${_initiator%%#*} ]] && continue # Skip comment lines case $_initiator in InitiatorName=*) initiator=${_initiator#InitiatorName=} echo "rd.iscsi.initiator=${initiator}" - return 0;; + return 0 + ;; *) ;; esac done < ${initiator_conf} @@ -763,15 +752,21 @@ kdump_get_iscsi_initiator() { # Figure out iBFT session according to session type is_ibft() { - [[ "$(kdump_iscsi_get_rec_val "$1" "node.discovery_type")" = fw ]] + [[ "$(kdump_iscsi_get_rec_val "$1" "node.discovery_type")" == fw ]] } kdump_setup_iscsi_device() { local path=$1 - local tgt_name; local tgt_ipaddr; - local username; local password; local userpwd_str; - local username_in; local password_in; local userpwd_in_str; - local netroot_str ; local initiator_str; + local tgt_name + local tgt_ipaddr + local username + local password + local userpwd_str + local username_in + local password_in + local userpwd_in_str + local netroot_str + local initiator_str local netroot_conf="${initdir}/etc/cmdline.d/50iscsi.conf" local initiator_conf="/etc/iscsi/initiatorname.iscsi" @@ -779,7 +774,7 @@ kdump_setup_iscsi_device() { # Check once before getting explicit values, so we can bail out early, # e.g. in case of pure-hardware(all-offload) iscsi. - if ! /sbin/iscsiadm -m session -r "$path" &>/dev/null ; then + if ! /sbin/iscsiadm -m session -r "$path" &> /dev/null; then return 1 fi @@ -796,18 +791,18 @@ kdump_setup_iscsi_device() { # get and set username and password details username=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username") - [[ "$username" == "" ]] && username="" + [[ $username == "" ]] && username="" password=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password") - [[ "$password" == "" ]] && password="" + [[ $password == "" ]] && password="" username_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username_in") - [[ -n "$username" ]] && userpwd_str="$username:$password" + [[ -n $username ]] && userpwd_str="$username:$password" # get and set incoming username and password details - [[ "$username_in" == "" ]] && username_in="" + [[ $username_in == "" ]] && username_in="" password_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password_in") - [[ "$password_in" == "" ]] && password_in="" + [[ $password_in == "" ]] && password_in="" - [[ -n "$username_in" ]] && userpwd_in_str=":$username_in:$password_in" + [[ -n $username_in ]] && userpwd_in_str=":$username_in:$password_in" kdump_install_net "$tgt_ipaddr" @@ -824,8 +819,8 @@ kdump_setup_iscsi_device() { # If netroot target does not exist already, append. if ! grep -q "$netroot_str" "$netroot_conf"; then - echo "$netroot_str" >> "$netroot_conf" - dinfo "Appended $netroot_str to $netroot_conf" + echo "$netroot_str" >> "$netroot_conf" + dinfo "Appended $netroot_str to $netroot_conf" fi # Setup initator @@ -836,14 +831,14 @@ kdump_setup_iscsi_device() { # If initiator details do not exist already, append. if ! grep -q "$initiator_str" "$netroot_conf"; then - echo "$initiator_str" >> "$netroot_conf" - dinfo "Appended $initiator_str to $netroot_conf" + echo "$initiator_str" >> "$netroot_conf" + dinfo "Appended $initiator_str to $netroot_conf" fi } -kdump_check_iscsi_targets () { +kdump_check_iscsi_targets() { # If our prerequisites are not met, fail anyways. - type -P iscsistart >/dev/null || return 1 + type -P iscsistart > /dev/null || return 1 kdump_check_setup_iscsi() ( local _dev @@ -869,12 +864,11 @@ get_alias() { local alias_set ips=$(hostname -I) - for ip in $ips - do - # in /etc/hosts, alias can come at the 2nd column - if entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }'); then - alias_set="$alias_set $entries" - fi + for ip in $ips; do + # in /etc/hosts, alias can come at the 2nd column + if entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }'); then + alias_set="$alias_set $entries" + fi done echo "$alias_set" @@ -892,7 +886,7 @@ is_localhost() { hostnames="$hostnames $shortnames $aliasname" for name in ${hostnames}; do - if [[ "$name" == "$nodename" ]]; then + if [[ $name == "$nodename" ]]; then return 0 fi done @@ -948,7 +942,7 @@ get_generic_fence_kdump_nodes() { # setup fence_kdump in cluster # setup proper network and install needed files -kdump_configure_fence_kdump () { +kdump_configure_fence_kdump() { local kdump_cfg_file=$1 local nodes local args @@ -963,7 +957,7 @@ kdump_configure_fence_kdump () { echo "fence_kdump_nodes $nodes" >> "${kdump_cfg_file}" args=$(get_pcs_fence_kdump_args) - if [[ -n "$args" ]]; then + if [[ -n $args ]]; then echo "fence_kdump_args $args" >> "${kdump_cfg_file}" fi @@ -987,14 +981,14 @@ kdump_configure_fence_kdump () { kdump_install_random_seed() { local poolsize - poolsize=$( /dev/null + bs="$poolsize" count=1 2> /dev/null } kdump_install_systemd_conf() { @@ -1071,8 +1065,8 @@ install() { # it unconditionally here, if "/etc/lvm/lvm.conf" doesn't exist, it # actually does nothing. sed -i -e \ - 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ - "${initdir}/etc/lvm/lvm.conf" &>/dev/null + 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ + "${initdir}/etc/lvm/lvm.conf" &> /dev/null # Save more memory by dropping switch root capability dracut_no_switch_root diff --git a/kdumpctl b/kdumpctl index d11c3c1..59ec068 100755 --- a/kdumpctl +++ b/kdumpctl @@ -46,7 +46,7 @@ single_instance_lock() { local rc timeout=5 - if ! exec 9>/var/lock/kdump; then + if ! exec 9> /var/lock/kdump; then derror "Create file lock failed" exit 1 fi @@ -90,9 +90,9 @@ save_core() # https://fedorahosted.org/abrt/ if [[ -x /usr/bin/dumpoops ]]; then ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" - makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" >/dev/null 2>&1 + makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" > /dev/null 2>&1 ddebug "dumpoops -d $coredir/dmesg" - if dumpoops -d "$coredir/dmesg" >/dev/null 2>&1; then + if dumpoops -d "$coredir/dmesg" > /dev/null 2>&1; then dinfo "kernel oops has been collected by abrt tool" fi fi @@ -131,7 +131,7 @@ rebuild_kdump_initrd() rebuild_initrd() { - if [[ ! -w $(dirname "$TARGET_INITRD") ]];then + if [[ ! -w $(dirname "$TARGET_INITRD") ]]; then derror "$(dirname "$TARGET_INITRD") does not have write permission. Cannot rebuild $TARGET_INITRD" return 1 fi @@ -149,7 +149,7 @@ rebuild_initrd() check_exist() { for file in $1; do - if [[ ! -e "$file" ]]; then + if [[ ! -e $file ]]; then derror "Error: $file not found." return 1 fi @@ -160,7 +160,7 @@ check_exist() check_executable() { for file in $1; do - if [[ ! -x "$file" ]]; then + if [[ ! -x $file ]]; then derror "Error: $file is not executable." return 1 fi @@ -171,7 +171,7 @@ backup_default_initrd() { ddebug "backup default initrd: $DEFAULT_INITRD" - if [[ ! -f "$DEFAULT_INITRD" ]]; then + if [[ ! -f $DEFAULT_INITRD ]]; then return fi @@ -190,7 +190,7 @@ restore_default_initrd() { ddebug "restore default initrd: $DEFAULT_INITRD" - if [[ ! -f "$DEFAULT_INITRD" ]]; then + if [[ ! -f $DEFAULT_INITRD ]]; then return fi @@ -200,7 +200,7 @@ restore_default_initrd() # verify checksum before restoring backup_checksum=$(sha1sum "$DEFAULT_INITRD_BAK" | awk '{ print $1 }') default_checksum=$(awk '{ print $1 }' "$INITRD_CHECKSUM_LOCATION") - if [[ "$default_checksum" != "$backup_checksum" ]]; then + if [[ $default_checksum != "$backup_checksum" ]]; then dwarn "WARNING: checksum mismatch! Can't restore original initrd.." else rm -f $INITRD_CHECKSUM_LOCATION @@ -220,7 +220,7 @@ check_config() dracut_args) if [[ $config_val == *--mount* ]]; then if [[ $(echo "$config_val" | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then - derror "Multiple mount targets specified in one \"dracut_args\"." + derror 'Multiple mount targets specified in one "dracut_args".' return 1 fi config_opt=_target @@ -232,12 +232,12 @@ check_config() fi config_opt=_target ;; - ext[234]|minix|btrfs|xfs|nfs|ssh) + ext[234] | minix | btrfs | xfs | nfs | ssh) config_opt=_target ;; - sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|failure_action|default|final_action|force_rebuild|force_no_rebuild|fence_kdump_args|fence_kdump_nodes) - ;; - net|options|link_delay|disk_timeout|debug_mem_level|blacklist) + sshkey | path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes) ;; + + net | options | link_delay | disk_timeout | debug_mem_level | blacklist) derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." return 1 ;; @@ -250,12 +250,12 @@ check_config() ;; esac - if [[ -z "$config_val" ]]; then + if [[ -z $config_val ]]; then derror "Invalid kdump config value for option '$config_opt'" return 1 fi - if [[ -n "${_opt_rec[$config_opt]}" ]]; then + if [[ -n ${_opt_rec[$config_opt]} ]]; then if [[ $config_opt == _target ]]; then derror "More than one dump targets specified" else @@ -291,7 +291,7 @@ get_pcs_cluster_modified_files() if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then time_stamp=$(stat -c "%Y" "$FENCE_KDUMP_CONFIG_FILE") - if [[ "$time_stamp" -gt "$image_time" ]]; then + if [[ $time_stamp -gt $image_time ]]; then modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE" fi fi @@ -335,14 +335,14 @@ check_files_modified() HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do - if [[ -x "$file" ]]; then + if [[ -x $file ]]; then POST_FILES="$POST_FILES $file" fi done fi if [[ -d /etc/kdump/pre.d ]]; then for file in /etc/kdump/pre.d/*; do - if [[ -x "$file" ]]; then + if [[ -x $file ]]; then PRE_FILES="$PRE_FILES $file" fi done @@ -359,19 +359,19 @@ check_files_modified() # Check for any updated extra module EXTRA_MODULES="$(kdump_get_conf_val extra_modules)" - if [[ -n "$EXTRA_MODULES" ]]; then + if [[ -n $EXTRA_MODULES ]]; then if [[ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]]; then files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" fi for _module in $EXTRA_MODULES; do - if _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2>/dev/null)"; then + if _module_file="$(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_module" 2> /dev/null)"; then files="$files $_module_file" for _dep_modules in $(modinfo -F depends "$_module" | tr ',' ' '); do - files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2>/dev/null)" + files="$files $(modinfo --set-version "$KDUMP_KERNELVER" --filename "$_dep_modules" 2> /dev/null)" done else # If it's not a module nor builtin, give an error - if ! ( modprobe --set-version "$KDUMP_KERNELVER" --dry-run "$_module" &>/dev/null ); then + if ! (modprobe --set-version "$KDUMP_KERNELVER" --dry-run "$_module" &> /dev/null); then dwarn "Module $_module not found" fi fi @@ -383,15 +383,15 @@ check_files_modified() check_exist "$files" && check_executable "$EXTRA_BINS" || return 2 for file in $files; do - if [[ -e "$file" ]]; then + if [[ -e $file ]]; then time_stamp=$(stat -c "%Y" "$file") - if [[ "$time_stamp" -gt "$image_time" ]]; then + if [[ $time_stamp -gt $image_time ]]; then modified_files="$modified_files $file" fi - if [[ -L "$file" ]]; then + if [[ -L $file ]]; then file=$(readlink -m "$file") time_stamp=$(stat -c "%Y" "$file") - if [[ "$time_stamp" -gt "$image_time" ]]; then + if [[ $time_stamp -gt $image_time ]]; then modified_files="$modified_files $file" fi fi @@ -400,7 +400,7 @@ check_files_modified() fi done - if [[ -n "$modified_files" ]]; then + if [[ -n $modified_files ]]; then dinfo "Detected change(s) in the following file(s): $modified_files" return 1 fi @@ -414,8 +414,9 @@ check_drivers_modified() # If it's dump target is on block device, detect the block driver _target=$(get_block_dump_target) - if [[ -n "$_target" ]]; then - _record_block_drivers() { + if [[ -n $_target ]]; then + _record_block_drivers() + { local _drivers _drivers=$(udevadm info -a "/dev/block/$1" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p') for _driver in $_drivers; do @@ -431,7 +432,7 @@ check_drivers_modified() # Include watchdog drivers if watchdog module is not omitted is_dracut_mod_omitted watchdog || _new_drivers+=" $(get_watchdog_drvs)" - [[ -z "$_new_drivers" ]] && return 0 + [[ -z $_new_drivers ]] && return 0 if is_fadump_capable; then _old_drivers="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/fadump-kernel-modules.txt | tr '\n' ' ')" @@ -443,9 +444,9 @@ check_drivers_modified() ddebug "Modules included in old initramfs: '$_old_drivers'" for _driver in $_new_drivers; do # Skip deprecated/invalid driver name or built-in module - _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2>/dev/null) - _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2>/dev/null) - if [[ -z "$_module_name" ]] || [[ -z "$_module_filename" ]] || [[ "$_module_filename" = *"(builtin)"* ]]; then + _module_name=$(modinfo --set-version "$KDUMP_KERNELVER" -F name "$_driver" 2> /dev/null) + _module_filename=$(modinfo --set-version "$KDUMP_KERNELVER" -n "$_driver" 2> /dev/null) + if [[ -z $_module_name ]] || [[ -z $_module_filename ]] || [[ $_module_filename == *"(builtin)"* ]]; then continue fi if ! [[ " $_old_drivers " == *" $_module_name "* ]]; then @@ -474,21 +475,21 @@ check_fs_modified() _target=$(get_block_dump_target) _new_fstype=$(get_fs_type_from_target "$_target") - if [[ -z "$_target" ]] || [[ -z "$_new_fstype" ]];then + if [[ -z $_target ]] || [[ -z $_new_fstype ]]; then derror "Dump target is invalid" return 2 fi ddebug "_target=$_target _new_fstype=$_new_fstype" _new_dev=$(kdump_get_persistent_dev "$_target") - if [[ -z "$_new_dev" ]]; then + if [[ -z $_new_dev ]]; then perror "Get persistent device name failed" return 2 fi _new_mntpoint="$(get_kdump_mntpoint_from_target "$_target")" _dracut_args=$(lsinitrd "$TARGET_INITRD" -f usr/lib/dracut/build-parameter.txt) - if [[ -z "$_dracut_args" ]];then + if [[ -z $_dracut_args ]]; then dwarn "Warning: No dracut arguments found in initrd" return 0 fi @@ -501,10 +502,10 @@ check_fs_modified() _old_dev=$1 _old_mntpoint=$2 _old_fstype=$3 - [[ $_new_dev = "$_old_dev" && $_new_mntpoint = "$_old_mntpoint" && $_new_fstype = "$_old_fstype" ]] && return 0 + [[ $_new_dev == "$_old_dev" && $_new_mntpoint == "$_old_mntpoint" && $_new_fstype == "$_old_fstype" ]] && return 0 # otherwise rebuild if target device is not a root device else - [[ "$_target" = "$(get_root_fs_device)" ]] && return 0 + [[ $_target == "$(get_root_fs_device)" ]] && return 0 fi dinfo "Detected change in File System" @@ -551,36 +552,36 @@ check_rebuild() force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) force_no_rebuild=${force_no_rebuild:-0} - if [[ "$force_no_rebuild" != "0" ]] && [[ "$force_no_rebuild" != "1" ]];then + if [[ $force_no_rebuild != "0" ]] && [[ $force_no_rebuild != "1" ]]; then derror "Error: force_no_rebuild value is invalid" return 1 fi force_rebuild=$(kdump_get_conf_val force_rebuild) force_rebuild=${force_rebuild:-0} - if [[ "$force_rebuild" != "0" ]] && [[ "$force_rebuild" != "1" ]];then + if [[ $force_rebuild != "0" ]] && [[ $force_rebuild != "1" ]]; then derror "Error: force_rebuild value is invalid" return 1 fi - if [[ "$force_no_rebuild" == "1" && "$force_rebuild" == "1" ]]; then + if [[ $force_no_rebuild == "1" && $force_rebuild == "1" ]]; then derror "Error: force_rebuild and force_no_rebuild are enabled simultaneously in kdump.conf" return 1 fi # Will not rebuild kdump initrd - if [[ "$force_no_rebuild" == "1" ]]; then + if [[ $force_no_rebuild == "1" ]]; then return 0 fi #check to see if dependent files has been modified #since last build of the image file if [[ -f $TARGET_INITRD ]]; then - image_time=$(stat -c "%Y" "$TARGET_INITRD" 2>/dev/null) + image_time=$(stat -c "%Y" "$TARGET_INITRD" 2> /dev/null) #in case of fadump mode, check whether the default/target #initrd is already built with dump capture capability - if [[ "$DEFAULT_DUMP_MODE" == "fadump" ]]; then + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$) fi fi @@ -589,17 +590,17 @@ check_rebuild() ret=$? if [[ $ret -eq 2 ]]; then return 1 - elif [[ $ret -eq 1 ]];then + elif [[ $ret -eq 1 ]]; then system_modified="1" fi if [[ $image_time -eq 0 ]]; then dinfo "No kdump initial ramdisk found." - elif [[ "$capture_capable_initrd" == "0" ]]; then + elif [[ $capture_capable_initrd == "0" ]]; then dinfo "Rebuild $TARGET_INITRD with dump capture support" - elif [[ "$force_rebuild" != "0" ]]; then + elif [[ $force_rebuild != "0" ]]; then dinfo "Force rebuild $TARGET_INITRD" - elif [[ "$system_modified" != "0" ]]; then + elif [[ $system_modified != "0" ]]; then : else return 0 @@ -617,13 +618,13 @@ function load_kdump_kernel_key() # this is only called inside is_secure_boot_enforced, # no need to retest - # this is only required if DT /ibm,secure-boot is a file. - # if it is a dir, we are on OpenPower and don't need this. - if ! [[ -f /proc/device-tree/ibm,secure-boot ]]; then - return - fi + # this is only required if DT /ibm,secure-boot is a file. + # if it is a dir, we are on OpenPower and don't need this. + if ! [[ -f /proc/device-tree/ibm,secure-boot ]]; then + return + fi - KDUMP_KEY_ID=$(keyctl padd asymmetric kernelkey-$RANDOM %:.ima < "/usr/share/doc/kernel-keys/$KDUMP_KERNELVER/kernel-signing-ppc.cer") + KDUMP_KEY_ID=$(keyctl padd asymmetric kernelkey-$RANDOM %:.ima < "/usr/share/doc/kernel-keys/$KDUMP_KERNELVER/kernel-signing-ppc.cer") } # remove a previously loaded key. There's no real security implication @@ -631,7 +632,7 @@ function load_kdump_kernel_key() # to be idempotent and so as to reduce the potential for confusion. function remove_kdump_kernel_key() { - if [[ -z "$KDUMP_KEY_ID" ]]; then + if [[ -z $KDUMP_KEY_ID ]]; then return fi @@ -696,7 +697,7 @@ check_ssh_config() case "$config_opt" in sshkey) # remove inline comments after the end of a directive. - if [[ -f "$config_val" ]]; then + if [[ -f $config_val ]]; then # canonicalize the path SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val") else @@ -709,14 +710,14 @@ check_ssh_config() ssh) DUMP_TARGET=$config_val ;; - *) - ;; + *) ;; + esac done <<< "$(kdump_read_conf)" #make sure they've configured kdump.conf for ssh dumps SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p') - if [[ -z "$SSH_TARGET" ]]; then + if [[ -z $SSH_TARGET ]]; then return 1 fi return 0 @@ -763,7 +764,7 @@ check_and_wait_network_ready() diff=$((cur - start_time)) # 60s time out if [[ $diff -gt 180 ]]; then - break; + break fi sleep 1 done @@ -814,19 +815,19 @@ propagate_ssh_key() show_reserved_mem() { - local mem - local mem_mb + local mem + local mem_mb - mem=$(/dev/null 2>&1; then + if makedumpfile -R "$coredir/vmcore" < "$raw_target" > /dev/null 2>&1; then # dump found dinfo "Dump saved to $coredir/vmcore" # wipe makedumpfile header - dd if=/dev/zero of="$raw_target" bs=1b count=1 2>/dev/null + dd if=/dev/zero of="$raw_target" bs=1b count=1 2> /dev/null else rm -rf "$coredir" fi @@ -897,11 +898,11 @@ path_to_be_relabeled() if is_user_configured_dump_target; then if is_mount_in_dracut_args; then - return; + return fi _target=$(local_fs_dump_target) - if [[ -n "$_target" ]]; then + if [[ -n $_target ]]; then _mnt=$(get_mntpoint_from_target "$_target") if ! is_mounted "$_mnt"; then return @@ -913,8 +914,8 @@ path_to_be_relabeled() _path=$(get_save_path) # if $_path is masked by other mount, we will not relabel it. - _rmnt=$(df "$_mnt/$_path" 2>/dev/null | tail -1 | awk '{ print $NF }') - if [[ "$_rmnt" == "$_mnt" ]]; then + _rmnt=$(df "$_mnt/$_path" 2> /dev/null | tail -1 | awk '{ print $NF }') + if [[ $_rmnt == "$_mnt" ]]; then echo "$_mnt/$_path" fi } @@ -924,14 +925,14 @@ selinux_relabel() local _path _i _attr _path=$(path_to_be_relabeled) - if [[ -z "$_path" ]] || ! [[ -d "$_path" ]] ; then + if [[ -z $_path ]] || ! [[ -d $_path ]]; then return fi while IFS= read -r -d '' _i; do - _attr=$(getfattr -m "security.selinux" "$_i" 2>/dev/null) - if [[ -z "$_attr" ]]; then - restorecon "$_i"; + _attr=$(getfattr -m "security.selinux" "$_i" 2> /dev/null) + if [[ -z $_attr ]]; then + restorecon "$_i" fi done < <(find "$_path" -print0) } @@ -947,7 +948,7 @@ check_fence_kdump_config() nodes=$(kdump_get_conf_val "fence_kdump_nodes") for node in $nodes; do - if [[ "$node" = "$hostname" ]]; then + if [[ $node == "$hostname" ]]; then derror "Option fence_kdump_nodes cannot contain $hostname" return 1 fi @@ -1003,25 +1004,26 @@ check_failure_action_config() default_option=$(kdump_get_conf_val default) failure_action=$(kdump_get_conf_val failure_action) - if [[ -z "$failure_action" ]] && [[ -z "$default_option" ]]; then + if [[ -z $failure_action ]] && [[ -z $default_option ]]; then return 0 - elif [[ -n "$failure_action" ]] && [[ -n "$default_option" ]]; then + elif [[ -n $failure_action ]] && [[ -n $default_option ]]; then derror "Cannot specify 'failure_action' and 'default' option together" return 1 fi - if [[ -n "$default_option" ]]; then + if [[ -n $default_option ]]; then option="default" failure_action="$default_option" fi case "$failure_action" in - reboot|halt|poweroff|shell|dump_to_rootfs) + reboot | halt | poweroff | shell | dump_to_rootfs) return 0 - ;; - *) + ;; + *) dinfo $"Usage kdump.conf: $option {reboot|halt|poweroff|shell|dump_to_rootfs}" return 1 + ;; esac } @@ -1030,16 +1032,17 @@ check_final_action_config() local final_action final_action=$(kdump_get_conf_val final_action) - if [[ -z "$final_action" ]]; then + if [[ -z $final_action ]]; then return 0 else case "$final_action" in - reboot|halt|poweroff) + reboot | halt | poweroff) return 0 - ;; - *) + ;; + *) dinfo $"Usage kdump.conf: final_action {reboot|halt|poweroff}" return 1 + ;; esac fi } @@ -1056,7 +1059,7 @@ start() return 1 fi - if sestatus 2>/dev/null | grep -q "SELinux status.*enabled"; then + if sestatus 2> /dev/null | grep -q "SELinux status.*enabled"; then selinux_relabel fi @@ -1187,7 +1190,8 @@ stop() return 0 } -rebuild() { +rebuild() +{ check_config || return 1 if check_ssh_config; then @@ -1203,33 +1207,34 @@ rebuild() { return $? } -do_estimate() { +do_estimate() +{ local kdump_mods local -A large_mods local baseline local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommended_size - local size_mb=$(( 1024 * 1024 )) + local size_mb=$((1024 * 1024)) setup_initrd - if [[ ! -f "$TARGET_INITRD" ]]; then + if [[ ! -f $TARGET_INITRD ]]; then derror "kdumpctl estimate: kdump initramfs is not built yet." exit 1 fi kdump_mods="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')" baseline=$(kdump_get_arch_recommend_size) - if [[ "${baseline: -1}" == "M" ]]; then + if [[ ${baseline: -1} == "M" ]]; then baseline=${baseline%M} - elif [[ "${baseline: -1}" == "G" ]]; then - baseline=$(( ${baseline%G} * 1024 )) - elif [[ "${baseline: -1}" == "T" ]]; then - baseline=$(( ${baseline%Y} * 1048576 )) + elif [[ ${baseline: -1} == "G" ]]; then + baseline=$((${baseline%G} * 1024)) + elif [[ ${baseline: -1} == "T" ]]; then + baseline=$((${baseline%Y} * 1048576)) fi # The default pre-reserved crashkernel value baseline_size=$((baseline * size_mb)) # Current reserved crashkernel size - reserved_size=$(" else echo "" @@ -1294,14 +1299,15 @@ do_estimate() { fi } -reset_crashkernel() { +reset_crashkernel() +{ local kernel=$1 entry crashkernel_default local grub_etc_default="/etc/default/grub" - [[ -z "$kernel" ]] && kernel=$(uname -r) - crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null) + [[ -z $kernel ]] && kernel=$(uname -r) + crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2> /dev/null) - if [[ -z "$crashkernel_default" ]]; then + if [[ -z $crashkernel_default ]]; then derror "$kernel doesn't have a crashkernel.default" exit 1 fi @@ -1318,7 +1324,7 @@ reset_crashkernel() { entry=${entry#\"} entry=${entry%\"} - if [[ -f "$grub_etc_default" ]]; then + if [[ -f $grub_etc_default ]]; then sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$crashkernel_default\2/" "$grub_etc_default" fi @@ -1328,18 +1334,18 @@ reset_crashkernel() { fi } -if [[ ! -f "$KDUMP_CONFIG_FILE" ]]; then +if [[ ! -f $KDUMP_CONFIG_FILE ]]; then derror "Error: No kdump config file found!" exit 1 fi -main () +main() { # Determine if the dump mode is kdump or fadump determine_dump_mode case "$1" in - start) + start) if [[ -s /proc/vmcore ]]; then save_core reboot @@ -1347,51 +1353,52 @@ main () start fi ;; - stop) + stop) stop ;; - status) + status) EXIT_CODE=0 check_current_status case "$?" in - 0) + 0) dinfo "Kdump is operational" EXIT_CODE=0 ;; - 1) + 1) dinfo "Kdump is not operational" EXIT_CODE=3 ;; esac exit $EXIT_CODE ;; - reload) + reload) reload ;; - restart) + restart) stop start ;; - rebuild) + rebuild) rebuild ;; - condrestart) - ;; - propagate) + condrestart) ;; + + propagate) propagate_ssh_key ;; - showmem) + showmem) show_reserved_mem ;; - estimate) + estimate) do_estimate ;; - reset-crashkernel) + reset-crashkernel) reset_crashkernel "$2" ;; - *) + *) dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}" exit 1 + ;; esac } @@ -1400,6 +1407,9 @@ single_instance_lock # To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call main. # So that fd isn't leaking when main is invoking a subshell. -(exec 9<&-; main "$@") +( + exec 9<&- + main "$@" +) exit $? diff --git a/mkdumprd b/mkdumprd index a027e6a..eebbbe1 100644 --- a/mkdumprd +++ b/mkdumprd @@ -27,7 +27,7 @@ SAVE_PATH=$(get_save_path) OVERRIDE_RESETTABLE=0 extra_modules="" -dracut_args=( --add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump" ) +dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump") MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." @@ -43,66 +43,71 @@ trap ' # clean up after ourselves no matter how we die. trap 'exit 1;' SIGINT -add_dracut_arg() { - dracut_args+=( "$@" ) +add_dracut_arg() +{ + dracut_args+=("$@") } -add_dracut_mount() { - add_dracut_arg "--mount" "$1" +add_dracut_mount() +{ + add_dracut_arg "--mount" "$1" } -add_dracut_sshkey() { - add_dracut_arg "--sshkey" "$1" +add_dracut_sshkey() +{ + add_dracut_arg "--sshkey" "$1" } # caller should ensure $1 is valid and mounted in 1st kernel -to_mount() { - local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev +to_mount() +{ + local _target=$1 _fstype=$2 _options=$3 _sed_cmd _new_mntpoint _pdev - _new_mntpoint=$(get_kdump_mntpoint_from_target "$_target") - _fstype="${_fstype:-$(get_fs_type_from_target "$_target")}" - _options="${_options:-$(get_mntopt_from_target "$_target")}" - _options="${_options:-defaults}" + _new_mntpoint=$(get_kdump_mntpoint_from_target "$_target") + _fstype="${_fstype:-$(get_fs_type_from_target "$_target")}" + _options="${_options:-$(get_mntopt_from_target "$_target")}" + _options="${_options:-defaults}" - if [[ "$_fstype" == "nfs"* ]]; then - _pdev=$_target - _sed_cmd+='s/,addr=[^,]*//;' - _sed_cmd+='s/,proto=[^,]*//;' - _sed_cmd+='s/,clientaddr=[^,]*//;' - else - # for non-nfs _target converting to use udev persistent name - _pdev="$(kdump_get_persistent_dev "$_target")" - if [[ -z $_pdev ]]; then - return 1 - fi - fi + if [[ $_fstype == "nfs"* ]]; then + _pdev=$_target + _sed_cmd+='s/,addr=[^,]*//;' + _sed_cmd+='s/,proto=[^,]*//;' + _sed_cmd+='s/,clientaddr=[^,]*//;' + else + # for non-nfs _target converting to use udev persistent name + _pdev="$(kdump_get_persistent_dev "$_target")" + if [[ -z $_pdev ]]; then + return 1 + fi + fi - # mount fs target as rw in 2nd kernel - _sed_cmd+='s/\(^\|,\)ro\($\|,\)/\1rw\2/g;' - # with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd - # kernel, filter it out here. - _sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;' - # drop nofail or nobootwait - _sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;' - _sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;' + # mount fs target as rw in 2nd kernel + _sed_cmd+='s/\(^\|,\)ro\($\|,\)/\1rw\2/g;' + # with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd + # kernel, filter it out here. + _sed_cmd+='s/\(^\|,\)noauto\($\|,\)/\1/g;' + # drop nofail or nobootwait + _sed_cmd+='s/\(^\|,\)nofail\($\|,\)/\1/g;' + _sed_cmd+='s/\(^\|,\)nobootwait\($\|,\)/\1/g;' - _options=$(echo "$_options" | sed "$_sed_cmd") + _options=$(echo "$_options" | sed "$_sed_cmd") - echo "$_pdev $_new_mntpoint $_fstype $_options" + echo "$_pdev $_new_mntpoint $_fstype $_options" } #Function: get_ssh_size #$1=dump target #called from while loop and shouldn't read from stdin, so we're using "ssh -n" -get_ssh_size() { - local _out - local _opt=("-i" "$SSH_KEY_LOCATION" "-o" "BatchMode=yes" "-o" "StrictHostKeyChecking=yes") +get_ssh_size() +{ + local _out + local _opt=("-i" "$SSH_KEY_LOCATION" "-o" "BatchMode=yes" "-o" "StrictHostKeyChecking=yes") - if ! _out=$(ssh -q -n "${_opt[@]}" "$1" "df" "--output=avail" "$SAVE_PATH"); then - perror_exit "checking remote ssh server available size failed." - fi + if ! _out=$(ssh -q -n "${_opt[@]}" "$1" "df" "--output=avail" "$SAVE_PATH"); then + perror_exit "checking remote ssh server available size failed." + fi - echo -n "$_out" | tail -1 + echo -n "$_out" | tail -1 } #mkdir if save path does not exist on ssh dump target @@ -111,320 +116,323 @@ get_ssh_size() { #called from while loop and shouldn't read from stdin, so we're using "ssh -n" mkdir_save_path_ssh() { - local _opt _dir - _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) - ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" &>/dev/null || \ - perror_exit "mkdir failed on $1:$SAVE_PATH" + local _opt _dir + _opt=(-i "$SSH_KEY_LOCATION" -o BatchMode=yes -o StrictHostKeyChecking=yes) + ssh -qn "${_opt[@]}" "$1" mkdir -p "$SAVE_PATH" &> /dev/null || + perror_exit "mkdir failed on $1:$SAVE_PATH" - # check whether user has write permission on $1:$SAVE_PATH - _dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2>/dev/null) || \ - perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" - ssh -qn "${_opt[@]}" "$1" rmdir "$_dir" + # check whether user has write permission on $1:$SAVE_PATH + _dir=$(ssh -qn "${_opt[@]}" "$1" mktemp -dqp "$SAVE_PATH" 2> /dev/null) || + perror_exit "Could not create temporary directory on $1:$SAVE_PATH. Make sure user has write permission on destination" + ssh -qn "${_opt[@]}" "$1" rmdir "$_dir" - return 0 + return 0 } #Function: get_fs_size #$1=dump target -get_fs_size() { - df --output=avail "$(get_mntpoint_from_target "$1")/$SAVE_PATH" | tail -1 +get_fs_size() +{ + df --output=avail "$(get_mntpoint_from_target "$1")/$SAVE_PATH" | tail -1 } #Function: get_raw_size #$1=dump target -get_raw_size() { - fdisk -s "$1" +get_raw_size() +{ + fdisk -s "$1" } #Function: check_size #$1: dump type string ('raw', 'fs', 'ssh') #$2: dump target -check_size() { - local avail memtotal +check_size() +{ + local avail memtotal - memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo) - case "$1" in - raw) - avail=$(get_raw_size "$2") - ;; - ssh) - avail=$(get_ssh_size "$2") - ;; - fs) - avail=$(get_fs_size "$2") - ;; - *) - return - esac || perror_exit "Check dump target size failed" + memtotal=$(awk '/MemTotal/{print $2}' /proc/meminfo) + case "$1" in + raw) + avail=$(get_raw_size "$2") + ;; + ssh) + avail=$(get_ssh_size "$2") + ;; + fs) + avail=$(get_fs_size "$2") + ;; + *) + return + ;; + esac || perror_exit "Check dump target size failed" - if [[ "$avail" -lt "$memtotal" ]]; then - dwarn "Warning: There might not be enough space to save a vmcore." - dwarn " The size of $2 should be greater than $memtotal kilo bytes." - fi + if [[ $avail -lt $memtotal ]]; then + dwarn "Warning: There might not be enough space to save a vmcore." + dwarn " The size of $2 should be greater than $memtotal kilo bytes." + fi } check_save_path_fs() { - local _path=$1 + local _path=$1 - if [[ ! -d $_path ]]; then - perror_exit "Dump path $_path does not exist." - fi + if [[ ! -d $_path ]]; then + perror_exit "Dump path $_path does not exist." + fi } mount_failure() { - local _target=$1 - local _mnt=$2 - local _fstype=$3 - local msg="Failed to mount $_target" + local _target=$1 + local _mnt=$2 + local _fstype=$3 + local msg="Failed to mount $_target" - if [[ -n "$_mnt" ]]; then - msg="$msg on $_mnt" - fi + if [[ -n $_mnt ]]; then + msg="$msg on $_mnt" + fi - msg="$msg for kdump preflight check." + msg="$msg for kdump preflight check." - if [[ $_fstype = "nfs" ]]; then - msg="$msg Please make sure nfs-utils has been installed." - fi + if [[ $_fstype == "nfs" ]]; then + msg="$msg Please make sure nfs-utils has been installed." + fi - perror_exit "$msg" + perror_exit "$msg" } check_user_configured_target() { - local _target=$1 _cfg_fs_type=$2 _mounted - local _mnt _opt _fstype + local _target=$1 _cfg_fs_type=$2 _mounted + local _mnt _opt _fstype - _mnt=$(get_mntpoint_from_target "$_target") - _opt=$(get_mntopt_from_target "$_target") - _fstype=$(get_fs_type_from_target "$_target") + _mnt=$(get_mntpoint_from_target "$_target") + _opt=$(get_mntopt_from_target "$_target") + _fstype=$(get_fs_type_from_target "$_target") - if [[ -n "$_fstype" ]]; then - # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf - [[ $_fstype = "nfs"* ]] && _fstype=nfs + if [[ -n $_fstype ]]; then + # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf + [[ $_fstype == "nfs"* ]] && _fstype=nfs - if [[ -n "$_cfg_fs_type" ]] && [[ "$_fstype" != "$_cfg_fs_type" ]]; then - perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\"" - fi - else - _fstype="$_cfg_fs_type" - _fstype="$_cfg_fs_type" - fi + if [[ -n $_cfg_fs_type ]] && [[ $_fstype != "$_cfg_fs_type" ]]; then + perror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\"" + fi + else + _fstype="$_cfg_fs_type" + _fstype="$_cfg_fs_type" + fi - # For noauto mount, mount it inplace with default value. - # Else use the temporary target directory - if [[ -n "$_mnt" ]]; then - if ! is_mounted "$_mnt"; then - if [[ $_opt = *",noauto"* ]]; then - mount "$_mnt" || mount_failure "$_target" "$_mnt" "$_fstype" - _mounted=$_mnt - else - perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" - fi - fi - else - _mnt=$MKDUMPRD_TMPMNT - mkdir -p "$_mnt" - mount "$_target" "$_mnt" -t "$_fstype" -o defaults || mount_failure "$_target" "" "$_fstype" - _mounted=$_mnt - fi + # For noauto mount, mount it inplace with default value. + # Else use the temporary target directory + if [[ -n $_mnt ]]; then + if ! is_mounted "$_mnt"; then + if [[ $_opt == *",noauto"* ]]; then + mount "$_mnt" || mount_failure "$_target" "$_mnt" "$_fstype" + _mounted=$_mnt + else + perror_exit "Dump target \"$_target\" is neither mounted nor configured as \"noauto\"" + fi + fi + else + _mnt=$MKDUMPRD_TMPMNT + mkdir -p "$_mnt" + mount "$_target" "$_mnt" -t "$_fstype" -o defaults || mount_failure "$_target" "" "$_fstype" + _mounted=$_mnt + fi - # For user configured target, use $SAVE_PATH as the dump path within the target - if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then - perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\"" - fi + # For user configured target, use $SAVE_PATH as the dump path within the target + if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then + perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\"" + fi - check_size fs "$_target" + check_size fs "$_target" - # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway - if [[ -n "$_mounted" ]]; then - umount -f -- "$_mounted" - fi + # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway + if [[ -n $_mounted ]]; then + umount -f -- "$_mounted" + fi } # $1: core_collector config value -verify_core_collector() { - local _cmd="${1%% *}" - local _params="${1#* }" +verify_core_collector() +{ + local _cmd="${1%% *}" + local _params="${1#* }" - if [[ "$_cmd" != "makedumpfile" ]]; then - if is_raw_dump_target; then - dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually." - fi - return - fi + if [[ $_cmd != "makedumpfile" ]]; then + if is_raw_dump_target; then + dwarn "Warning: specifying a non-makedumpfile core collector, you will have to recover the vmcore manually." + fi + return + fi - if is_ssh_dump_target || is_raw_dump_target; then - if ! strstr "$_params" "-F"; then - perror_exit "The specified dump target needs makedumpfile \"-F\" option." - fi - _params="$_params vmcore" - else - _params="$_params vmcore dumpfile" - fi + if is_ssh_dump_target || is_raw_dump_target; then + if ! strstr "$_params" "-F"; then + perror_exit 'The specified dump target needs makedumpfile "-F" option.' + fi + _params="$_params vmcore" + else + _params="$_params vmcore dumpfile" + fi - # shellcheck disable=SC2086 - if ! $_cmd --check-params $_params; then - perror_exit "makedumpfile parameter check failed." - fi + # shellcheck disable=SC2086 + if ! $_cmd --check-params $_params; then + perror_exit "makedumpfile parameter check failed." + fi } -add_mount() { - local _mnt +add_mount() +{ + local _mnt - _mnt=$(to_mount "$@") || exit 1 + _mnt=$(to_mount "$@") || exit 1 - add_dracut_mount "$_mnt" + add_dracut_mount "$_mnt" } #handle the case user does not specify the dump target explicitly handle_default_dump_target() { - local _target - local _mntpoint + local _target + local _mntpoint - is_user_configured_dump_target && return + is_user_configured_dump_target && return - check_save_path_fs "$SAVE_PATH" + check_save_path_fs "$SAVE_PATH" - _save_path=$(get_bind_mount_source "$SAVE_PATH") - _target=$(get_target_from_path "$_save_path") - _mntpoint=$(get_mntpoint_from_target "$_target") + _save_path=$(get_bind_mount_source "$SAVE_PATH") + _target=$(get_target_from_path "$_save_path") + _mntpoint=$(get_mntpoint_from_target "$_target") - SAVE_PATH=${_save_path##"$_mntpoint"} - add_mount "$_target" - check_size fs "$_target" + SAVE_PATH=${_save_path##"$_mntpoint"} + add_mount "$_target" + check_size fs "$_target" } # $1: function name for_each_block_target() { - local dev majmin + local dev majmin - for dev in $(get_kdump_targets); do - [[ -b "$dev" ]] || continue - majmin=$(get_maj_min "$dev") - check_block_and_slaves "$1" "$majmin" && return 1 - done + for dev in $(get_kdump_targets); do + [[ -b $dev ]] || continue + majmin=$(get_maj_min "$dev") + check_block_and_slaves "$1" "$majmin" && return 1 + done - return 0 + return 0 } #judge if a specific device with $1 is unresettable #return false if unresettable. is_unresettable() { - local path device resettable=1 + local path device resettable=1 - path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" - if [[ -f "$path" ]]; then - resettable="$(<"$path")" - [[ $resettable -eq 0 ]] && [[ "$OVERRIDE_RESETTABLE" -eq 0 ]] && { - device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') - derror "Error: Can not save vmcore because device $device is unresettable" - return 0 - } - fi + path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" + if [[ -f $path ]]; then + resettable="$(< "$path")" + [[ $resettable -eq 0 ]] && [[ $OVERRIDE_RESETTABLE -eq 0 ]] && { + device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') + derror "Error: Can not save vmcore because device $device is unresettable" + return 0 + } + fi - return 1 + return 1 } #check if machine is resettable. #return true if resettable check_resettable() { - local _target _override_resettable + local _target _override_resettable - _override_resettable=$(kdump_get_conf_val override_resettable) - OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE} - if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ];then - perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid" - fi + _override_resettable=$(kdump_get_conf_val override_resettable) + OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE} + if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ]; then + perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid" + fi - for_each_block_target is_unresettable && return + for_each_block_target is_unresettable && return - return 1 + return 1 } check_crypt() { - local _dev + local _dev - for _dev in $(get_kdump_targets); do - if [[ -n $(get_luks_crypt_dev "$(get_maj_min "$_dev")") ]]; then - derror "Device $_dev is encrypted." && return 1 - fi - done + for _dev in $(get_kdump_targets); do + if [[ -n $(get_luks_crypt_dev "$(get_maj_min "$_dev")") ]]; then + derror "Device $_dev is encrypted." && return 1 + fi + done } if ! check_resettable; then - exit 1 + exit 1 fi if ! check_crypt; then - dwarn "Warning: Encrypted device is in dump path, which is not recommended, see kexec-kdump-howto.txt for more details." + dwarn "Warning: Encrypted device is in dump path, which is not recommended, see kexec-kdump-howto.txt for more details." fi # firstly get right SSH_KEY_LOCATION keyfile=$(kdump_get_conf_val sshkey) -if [[ -f "$keyfile" ]]; then - # canonicalize the path - SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$keyfile") +if [[ -f $keyfile ]]; then + # canonicalize the path + SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$keyfile") fi -while read -r config_opt config_val; -do - # remove inline comments after the end of a directive. - case "$config_opt" in - extra_modules) - extra_modules="$extra_modules $config_val" - ;; - ext[234]|xfs|btrfs|minix|nfs) - check_user_configured_target "$config_val" "$config_opt" - add_mount "$config_val" "$config_opt" - ;; - raw) - # checking raw disk writable - dd if="$config_val" count=1 of=/dev/null > /dev/null 2>&1 || { - perror_exit "Bad raw disk $config_val" - } - _praw=$(persistent_policy="by-id" kdump_get_persistent_dev "$config_val") - if [[ -z $_praw ]]; then - exit 1 - fi - add_dracut_arg "--device" "$_praw" - check_size raw "$config_val" - ;; - ssh) - if strstr "$config_val" "@"; - then - mkdir_save_path_ssh "$config_val" - check_size ssh "$config_val" - add_dracut_sshkey "$SSH_KEY_LOCATION" - else - perror_exit "Bad ssh dump target $config_val" - fi - ;; - core_collector) - verify_core_collector "$config_val" - ;; - dracut_args) - while read -r dracut_arg; do - add_dracut_arg "$dracut_arg" - done <<< "$(echo "$config_val" | xargs -n 1 echo)" - ;; - *) - ;; - esac +while read -r config_opt config_val; do + # remove inline comments after the end of a directive. + case "$config_opt" in + extra_modules) + extra_modules="$extra_modules $config_val" + ;; + ext[234] | xfs | btrfs | minix | nfs) + check_user_configured_target "$config_val" "$config_opt" + add_mount "$config_val" "$config_opt" + ;; + raw) + # checking raw disk writable + dd if="$config_val" count=1 of=/dev/null > /dev/null 2>&1 || { + perror_exit "Bad raw disk $config_val" + } + _praw=$(persistent_policy="by-id" kdump_get_persistent_dev "$config_val") + if [[ -z $_praw ]]; then + exit 1 + fi + add_dracut_arg "--device" "$_praw" + check_size raw "$config_val" + ;; + ssh) + if strstr "$config_val" "@"; then + mkdir_save_path_ssh "$config_val" + check_size ssh "$config_val" + add_dracut_sshkey "$SSH_KEY_LOCATION" + else + perror_exit "Bad ssh dump target $config_val" + fi + ;; + core_collector) + verify_core_collector "$config_val" + ;; + dracut_args) + while read -r dracut_arg; do + add_dracut_arg "$dracut_arg" + done <<< "$(echo "$config_val" | xargs -n 1 echo)" + ;; + *) ;; + + esac done <<< "$(kdump_read_conf)" handle_default_dump_target -if [[ -n "$extra_modules" ]] -then - add_dracut_arg "--add-drivers" "$extra_modules" +if [[ -n $extra_modules ]]; then + add_dracut_arg "--add-drivers" "$extra_modules" fi # TODO: The below check is not needed anymore with the introduction of @@ -433,11 +441,11 @@ fi # parameter available in fadump case. So, find a way to fix that first # before removing this check. if ! is_fadump_capable; then - # The 2nd rootfs mount stays behind the normal dump target mount, - # so it doesn't affect the logic of check_dump_fs_modified(). - is_dump_to_rootfs && add_mount "$(to_dev_name "$(get_root_fs_device)")" + # The 2nd rootfs mount stays behind the normal dump target mount, + # so it doesn't affect the logic of check_dump_fs_modified(). + is_dump_to_rootfs && add_mount "$(to_dev_name "$(get_root_fs_device)")" - add_dracut_arg "--no-hostonly-default-device" + add_dracut_arg "--no-hostonly-default-device" fi dracut "${dracut_args[@]}" "$@" diff --git a/mkfadumprd b/mkfadumprd index 5c96ee7..b890f83 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -44,22 +44,22 @@ fi ### Unpack the initramfs having dump capture capability mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot" -if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" && \ +if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" && popd > /dev/null); then derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'" exit 1 fi ### Pack it into the normal boot initramfs with zz-fadumpinit module -_dracut_isolate_args=(\ - --rebuild "$REBUILD_INITRD" --add zz-fadumpinit \ +_dracut_isolate_args=( + --rebuild "$REBUILD_INITRD" --add zz-fadumpinit -i "$MKFADUMPRD_TMPDIR/fadumproot" /fadumproot -i "$MKFADUMPRD_TMPDIR/fadumproot/usr/lib/dracut/hostonly-kernel-modules.txt" /usr/lib/dracut/fadump-kernel-modules.txt ) if is_squash_available; then - _dracut_isolate_args+=( --add squash ) + _dracut_isolate_args+=(--add squash) fi if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then From a5faa052d4969cb66719d0b795d746449d3c71b7 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 14 Sep 2021 03:25:46 +0800 Subject: [PATCH 127/454] kdump-lib-initramfs.sh: prepare to be a POSIX compatible lib Move all functions needed in the second kernel from kdump-lib.sh to kdump-lib-initramfs.sh, and update shebang headers. Now, kdump-lib-initramfs.sh is an independent lib script, no longer depend on kdump-lib.sh, and kdump-lib.sh is no longer needed for the second kernel. In later commits, functions in kdump-lib-initramfs.sh will be reworked to be POSIX compatible, kdump-lib.sh will contain bash only functions. POSIX shell have very limited features, eg. `local` keyword doesn't exist in POSIX but we rely on that heavily. So kdump-lib.sh will use bash syntax and contain the most complex helper and codes. kdump-lib-initramfs.sh will contain the minimum set of helpers, and be shared by both the first and second kernel. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- .editorconfig | 2 +- dracut-module-setup.sh | 1 - kdump-lib-initramfs.sh | 133 ++++++++++++++++++++++++++++++++++++++++- kdump-lib.sh | 131 +--------------------------------------- 4 files changed, 135 insertions(+), 132 deletions(-) diff --git a/.editorconfig b/.editorconfig index bd8fc8c..87c4f98 100644 --- a/.editorconfig +++ b/.editorconfig @@ -18,7 +18,7 @@ binary_next_line = false space_redirects = true # Some scripts will only run with bash -[{mkfadumprd,mkdumprd,kdumpctl}] +[{mkfadumprd,mkdumprd,kdumpctl,kdump-lib.sh}] shell_variant = bash # Use dracut code style for *-module-setup.sh diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 8bbf0cf..4fb013d 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1034,7 +1034,6 @@ install() { inst "/usr/bin/printf" "/sbin/printf" inst "/usr/bin/logger" "/sbin/logger" inst "/usr/bin/chmod" "/sbin/chmod" - inst "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh" inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh" inst "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh" inst "$moddir/kdump.sh" "/usr/bin/kdump.sh" diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 50443e5..73b2699 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -1,8 +1,11 @@ -# These variables and functions are useful in 2nd kernel +#!/bin/sh +# +# Function and variables used in initramfs environment, POSIX compatible +# -. /lib/kdump-lib.sh . /lib/kdump-logger.sh +DEFAULT_PATH="/var/crash/" KDUMP_PATH="/var/crash" KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log" CORE_COLLECTOR="" @@ -20,6 +23,7 @@ KDUMP_PRE="" KDUMP_POST="" NEWROOT="/sysroot" OPALCORE="/sys/firmware/opal/mpipl/core" +KDUMP_CONFIG_FILE="/etc/kdump.conf" #initiate the kdump logger dlog_init @@ -28,6 +32,131 @@ if [ $? -ne 0 ]; then exit 1 fi +# Read kdump config in well formated style +kdump_read_conf() +{ + # Following steps are applied in order: strip trailing comment, strip trailing space, + # strip heading space, match non-empty line, remove duplicated spaces between conf name and value + [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE +} + +# Retrieves config value defined in kdump.conf +# $1: config name, sed regexp compatible +kdump_get_conf_val() { + # For lines matching "^\s*$1\s+", remove matched part (config name including space), + # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. + [ -f "$KDUMP_CONFIG_FILE" ] && \ + sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE +} + +is_mounted() +{ + findmnt -k -n $1 &>/dev/null +} + +get_mount_info() +{ + local _info_type=$1 _src_type=$2 _src=$3; shift 3 + local _info=$(findmnt -k -n -r -o $_info_type --$_src_type $_src $@) + + [ -z "$_info" ] && [ -e "/etc/fstab" ] && _info=$(findmnt -s -n -r -o $_info_type --$_src_type $_src $@) + + echo $_info +} + +is_ipv6_address() +{ + echo $1 | grep -q ":" +} + +is_fs_type_nfs() +{ + [ "$1" = "nfs" ] || [ "$1" = "nfs4" ] +} + +# If $1 contains dracut_args "--mount", return +get_dracut_args_fstype() +{ + echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3 +} + +# If $1 contains dracut_args "--mount", return +get_dracut_args_target() +{ + echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1 +} + +get_save_path() +{ + local _save_path=$(kdump_get_conf_val path) + [ -z "$_save_path" ] && _save_path=$DEFAULT_PATH + + # strip the duplicated "/" + echo $_save_path | tr -s / +} + +get_root_fs_device() +{ + findmnt -k -f -n -o SOURCE / +} + +# Return the current underlying device of a path, ignore bind mounts +get_target_from_path() +{ + local _target + + _target=$(df $1 2>/dev/null | tail -1 | awk '{print $1}') + [[ "$_target" == "/dev/root" ]] && [[ ! -e /dev/root ]] && _target=$(get_root_fs_device) + echo $_target +} + +get_fs_type_from_target() +{ + get_mount_info FSTYPE source $1 -f +} + +get_mntpoint_from_target() +{ + # --source is applied to ensure non-bind mount is returned + get_mount_info TARGET source $1 -f +} + +is_ssh_dump_target() +{ + [[ $(kdump_get_conf_val ssh) == *@* ]] +} + +is_raw_dump_target() +{ + [[ $(kdump_get_conf_val raw) ]] +} + +is_nfs_dump_target() +{ + if [[ $(kdump_get_conf_val nfs) ]]; then + return 0; + fi + + if is_fs_type_nfs $(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)"); then + return 0 + fi + + local _save_path=$(get_save_path) + local _target=$(get_target_from_path $_save_path) + local _fstype=$(get_fs_type_from_target $_target) + + if is_fs_type_nfs $_fstype; then + return 0 + fi + + return 1 +} + +is_fs_dump_target() +{ + [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix") ]] +} + get_kdump_confs() { local config_opt config_val diff --git a/kdump-lib.sh b/kdump-lib.sh index 7e620c7..d7cb40e 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -1,13 +1,13 @@ -#!/bin/sh +#!/bin/bash # # Kdump common variables and functions # -DEFAULT_PATH="/var/crash/" +. /usr/lib/kdump/kdump-lib-initramfs.sh + FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" -KDUMP_CONFIG_FILE="/etc/kdump.conf" is_fadump_capable() { @@ -35,64 +35,6 @@ perror_exit() { exit 1 } -is_fs_type_nfs() -{ - [ "$1" = "nfs" ] || [ "$1" = "nfs4" ] -} - -is_ssh_dump_target() -{ - [[ $(kdump_get_conf_val ssh) == *@* ]] -} - -is_nfs_dump_target() -{ - if [[ $(kdump_get_conf_val nfs) ]]; then - return 0; - fi - - if is_fs_type_nfs $(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)"); then - return 0 - fi - - local _save_path=$(get_save_path) - local _target=$(get_target_from_path $_save_path) - local _fstype=$(get_fs_type_from_target $_target) - - if is_fs_type_nfs $_fstype; then - return 0 - fi - - return 1 -} - -is_raw_dump_target() -{ - [[ $(kdump_get_conf_val raw) ]] -} - -is_fs_dump_target() -{ - [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix") ]] -} - -# Read kdump config in well formatted style -kdump_read_conf() -{ - # Following steps are applied in order: strip trailing comment, strip trailing space, - # strip heading space, match non-empty line, remove duplicated spaces between conf name and value - [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE -} - -# Retrieves config value defined in kdump.conf -# $1: config name, sed regexp compatible -kdump_get_conf_val() { - # For lines matching "^\s*$1\s+", remove matched part (config name including space), - # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. - [ -f "$KDUMP_CONFIG_FILE" ] && \ - sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE -} - # Check if fence kdump is configured in Pacemaker cluster is_pcs_fence_kdump() { @@ -142,20 +84,6 @@ get_user_configured_dump_disk() [ -b "$_target" ] && echo $_target } -get_root_fs_device() -{ - findmnt -k -f -n -o SOURCE / -} - -get_save_path() -{ - local _save_path=$(kdump_get_conf_val path) - [ -z "$_save_path" ] && _save_path=$DEFAULT_PATH - - # strip the duplicated "/" - echo $_save_path | tr -s / -} - get_block_dump_target() { local _target _path @@ -261,46 +189,10 @@ get_bind_mount_source() echo $_mnt$_fsroot$_path } -# Return the current underlaying device of a path, ignore bind mounts -get_target_from_path() -{ - local _target - - _target=$(df $1 2>/dev/null | tail -1 | awk '{print $1}') - [[ "$_target" == "/dev/root" ]] && [[ ! -e /dev/root ]] && _target=$(get_root_fs_device) - echo $_target -} - -is_mounted() -{ - findmnt -k -n $1 &>/dev/null -} - -get_mount_info() -{ - local _info_type=$1 _src_type=$2 _src=$3; shift 3 - local _info=$(findmnt -k -n -r -o $_info_type --$_src_type $_src $@) - - [ -z "$_info" ] && [ -e "/etc/fstab" ] && _info=$(findmnt -s -n -r -o $_info_type --$_src_type $_src $@) - - echo $_info -} - -get_fs_type_from_target() -{ - get_mount_info FSTYPE source $1 -f -} - get_mntopt_from_target() { get_mount_info OPTIONS source $1 -f } -# Find the general mount point of a dump target, not the bind mount point -get_mntpoint_from_target() -{ - # Expcilitly specify --source to findmnt could ensure non-bind mount is returned - get_mount_info TARGET source $1 -f -} # Get the path where the target will be mounted in kdump kernel # $1: kdump target device @@ -345,11 +237,6 @@ is_atomic() grep -q "ostree" /proc/cmdline } -is_ipv6_address() -{ - echo $1 | grep -q ":" -} - # get ip address or hostname from nfs/ssh config value get_remote_host() { @@ -562,18 +449,6 @@ is_mount_in_dracut_args() [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] } -# If $1 contains dracut_args "--mount", return -get_dracut_args_fstype() -{ - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3 -} - -# If $1 contains dracut_args "--mount", return -get_dracut_args_target() -{ - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1 -} - check_crash_mem_reserved() { local mem_reserved From e7118d1de84b604b25b2f6332f4ae071a9dc08fd Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 2 Aug 2021 00:50:22 +0800 Subject: [PATCH 128/454] Merge kdump-error-handler.sh into kdump.sh kdump-error-handler.sh does nothing except calling three functions, it can be easily merged into kdump.sh by using a parameter to run the error handling routine. kdump-lib-initramfs.sh was created to hold the three shared functions and related code, so by merging these two files, kdump-lib-initramfs.sh can be simplified by a lot. Following up commits will clean up kdump-lib-initramfs.sh. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump-emergency.service | 2 +- dracut-kdump-error-handler.sh | 10 ---------- dracut-kdump.sh | 21 ++++++++++++++++----- dracut-module-setup.sh | 1 - kexec-tools.spec | 2 -- 5 files changed, 17 insertions(+), 19 deletions(-) delete mode 100755 dracut-kdump-error-handler.sh diff --git a/dracut-kdump-emergency.service b/dracut-kdump-emergency.service index f2f6fad..0cf7051 100644 --- a/dracut-kdump-emergency.service +++ b/dracut-kdump-emergency.service @@ -12,7 +12,7 @@ Environment=HOME=/ Environment=DRACUT_SYSTEMD=1 Environment=NEWROOT=/sysroot WorkingDirectory=/ -ExecStart=/bin/kdump-error-handler.sh +ExecStart=/bin/kdump.sh --error-handler ExecStopPost=-/bin/rm -f -- /.console_lock Type=oneshot StandardInput=tty-force diff --git a/dracut-kdump-error-handler.sh b/dracut-kdump-error-handler.sh deleted file mode 100755 index fc2b932..0000000 --- a/dracut-kdump-error-handler.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -. /lib/kdump-lib-initramfs.sh - -set -o pipefail -export PATH=$PATH:$KDUMP_SCRIPT_DIR - -get_kdump_confs -do_failure_action -do_final_action diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 3c165b3..352cad5 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -1,9 +1,7 @@ #!/bin/sh - -# continue here only if we have to save dump. -if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ] && [ ! -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then - exit 0 -fi +# +# The main kdump routine in capture kernel +# . /lib/dracut-lib.sh . /lib/kdump-lib-initramfs.sh @@ -288,6 +286,19 @@ fence_kdump_notify() fi } +if [ "$1" = "--error-handler" ]; then + get_kdump_confs + do_failure_action + do_final_action + + exit $? +fi + +# continue here only if we have to save dump. +if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ] && [ ! -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then + exit 0 +fi + read_kdump_confs fence_kdump_notify diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 4fb013d..d6011ee 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1039,7 +1039,6 @@ install() { inst "$moddir/kdump.sh" "/usr/bin/kdump.sh" inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service" systemctl -q --root "$initdir" add-wants initrd.target kdump-capture.service - inst "$moddir/kdump-error-handler.sh" "/usr/bin/kdump-error-handler.sh" # Replace existing emergency service and emergency target cp "$moddir/kdump-emergency.service" "$initdir/$systemdsystemunitdir/emergency.service" cp "$moddir/kdump-emergency.target" "$initdir/$systemdsystemunitdir/emergency.target" diff --git a/kexec-tools.spec b/kexec-tools.spec index 7db9f9c..f71ff81 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -52,7 +52,6 @@ Source36: kdump-restart.sh Source100: dracut-kdump.sh Source101: dracut-module-setup.sh Source102: dracut-monitor_dd_progress -Source103: dracut-kdump-error-handler.sh Source104: dracut-kdump-emergency.service Source106: dracut-kdump-capture.service Source107: dracut-kdump-emergency.target @@ -241,7 +240,6 @@ mkdir -p -m755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpba cp %{SOURCE100} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE100}} cp %{SOURCE101} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE101}} cp %{SOURCE102} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE102}} -cp %{SOURCE103} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE103}} cp %{SOURCE104} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE104}} cp %{SOURCE106} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE106}} cp %{SOURCE107} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE107}} From a1205effaa98c08974c39c3283d191c70337857a Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 5 Aug 2021 00:59:29 +0800 Subject: [PATCH 129/454] kdump-lib-initramfs.sh: move dump related functions to kdump.sh These dump related functions are only used by dracut-kdump.sh. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 288 ++++++++++++++++++++++++++++++++++++++++ kdump-lib-initramfs.sh | 289 ----------------------------------------- 2 files changed, 288 insertions(+), 289 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 352cad5..a785ab9 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -4,13 +4,301 @@ # . /lib/dracut-lib.sh +. /lib/kdump-logger.sh . /lib/kdump-lib-initramfs.sh +#initiate the kdump logger +dlog_init +if [ $? -ne 0 ]; then + echo "failed to initiate the kdump logger." + exit 1 +fi + +KDUMP_PATH="/var/crash" +KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log" +CORE_COLLECTOR="" +DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31" +DMESG_COLLECTOR="/sbin/vmcore-dmesg" +FAILURE_ACTION="systemctl reboot -f" +DATEDIR=`date +%Y-%m-%d-%T` +HOST_IP='127.0.0.1' +DUMP_INSTRUCTION="" +SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" +KDUMP_SCRIPT_DIR="/kdumpscripts" +DD_BLKSIZE=512 +FINAL_ACTION="systemctl reboot -f" +KDUMP_PRE="" +KDUMP_POST="" +NEWROOT="/sysroot" +OPALCORE="/sys/firmware/opal/mpipl/core" + set -o pipefail DUMP_RETVAL=0 export PATH=$PATH:$KDUMP_SCRIPT_DIR +get_kdump_confs() +{ + local config_opt config_val + + while read config_opt config_val; + do + # remove inline comments after the end of a directive. + case "$config_opt" in + path) + KDUMP_PATH="$config_val" + ;; + core_collector) + [ -n "$config_val" ] && CORE_COLLECTOR="$config_val" + ;; + sshkey) + if [ -f "$config_val" ]; then + SSH_KEY_LOCATION=$config_val + fi + ;; + kdump_pre) + KDUMP_PRE="$config_val" + ;; + kdump_post) + KDUMP_POST="$config_val" + ;; + fence_kdump_args) + FENCE_KDUMP_ARGS="$config_val" + ;; + fence_kdump_nodes) + FENCE_KDUMP_NODES="$config_val" + ;; + failure_action|default) + case $config_val in + shell) + FAILURE_ACTION="kdump_emergency_shell" + ;; + reboot) + FAILURE_ACTION="systemctl reboot -f && exit" + ;; + halt) + FAILURE_ACTION="halt && exit" + ;; + poweroff) + FAILURE_ACTION="systemctl poweroff -f && exit" + ;; + dump_to_rootfs) + FAILURE_ACTION="dump_to_rootfs" + ;; + esac + ;; + final_action) + case $config_val in + reboot) + FINAL_ACTION="systemctl reboot -f" + ;; + halt) + FINAL_ACTION="halt" + ;; + poweroff) + FINAL_ACTION="systemctl poweroff -f" + ;; + esac + ;; + esac + done <<< "$(kdump_read_conf)" + + if [ -z "$CORE_COLLECTOR" ]; then + CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" + if is_ssh_dump_target || is_raw_dump_target; then + CORE_COLLECTOR="$CORE_COLLECTOR -F" + fi + fi +} + +# store the kexec kernel log to a file. +save_log() +{ + dmesg -T > $KDUMP_LOG_FILE + + if command -v journalctl > /dev/null; then + journalctl -ab >> $KDUMP_LOG_FILE + fi + chmod 600 $KDUMP_LOG_FILE +} + +# dump_fs +dump_fs() +{ + local _exitcode + local _mp=$1 + local _op=$(get_mount_info OPTIONS target $_mp -f) + ddebug "dump_fs _mp=$_mp _opts=$_op" + + if ! is_mounted "$_mp"; then + dinfo "dump path \"$_mp\" is not mounted, trying to mount..." + mount --target $_mp + if [ $? -ne 0 ]; then + derror "failed to dump to \"$_mp\", it's not a mount point!" + return 1 + fi + fi + + # Remove -F in makedumpfile case. We don't want a flat format dump here. + [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"` + + local _dump_path=$(echo "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) + + dinfo "saving to $_dump_path" + + # Only remount to read-write mode if the dump target is mounted read-only. + if [[ "$_op" = "ro"* ]]; then + dinfo "Remounting the dump target in rw mode." + mount -o remount,rw $_mp || return 1 + fi + + mkdir -p $_dump_path || return 1 + + save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_path" + save_opalcore_fs "$_dump_path" + + dinfo "saving vmcore" + $CORE_COLLECTOR /proc/vmcore $_dump_path/vmcore-incomplete + _exitcode=$? + if [ $_exitcode -eq 0 ]; then + mv $_dump_path/vmcore-incomplete $_dump_path/vmcore + sync + dinfo "saving vmcore complete" + else + derror "saving vmcore failed, _exitcode:$_exitcode" + fi + + dinfo "saving the $KDUMP_LOG_FILE to $_dump_path/" + save_log + mv $KDUMP_LOG_FILE $_dump_path/ + if [ $_exitcode -ne 0 ]; then + return 1 + fi + + # improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure + return 0 +} + +save_vmcore_dmesg_fs() { + local _dmesg_collector=$1 + local _path=$2 + + dinfo "saving vmcore-dmesg.txt to ${_path}" + $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt + _exitcode=$? + if [ $_exitcode -eq 0 ]; then + mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt + chmod 600 ${_path}/vmcore-dmesg.txt + + # Make sure file is on disk. There have been instances where later + # saving vmcore failed and system rebooted without sync and there + # was no vmcore-dmesg.txt available. + sync + dinfo "saving vmcore-dmesg.txt complete" + else + if [ -f ${_path}/vmcore-dmesg-incomplete.txt ]; then + chmod 600 ${_path}/vmcore-dmesg-incomplete.txt + fi + derror "saving vmcore-dmesg.txt failed" + fi +} + +save_opalcore_fs() { + local _path=$1 + + if [ ! -f $OPALCORE ]; then + # Check if we are on an old kernel that uses a different path + if [ -f /sys/firmware/opal/core ]; then + OPALCORE="/sys/firmware/opal/core" + else + return 0 + fi + fi + + dinfo "saving opalcore:$OPALCORE to ${_path}/opalcore" + cp $OPALCORE ${_path}/opalcore + if [ $? -ne 0 ]; then + derror "saving opalcore failed" + return 1 + fi + + sync + dinfo "saving opalcore complete" + return 0 +} + +dump_to_rootfs() +{ + + if [[ $(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p") == "inactive" ]]; then + dinfo "Trying to bring up initqueue for rootfs mount" + systemctl start dracut-initqueue + fi + + dinfo "Clean up dead systemd services" + systemctl cancel + dinfo "Waiting for rootfs mount, will timeout after 90 seconds" + systemctl start --no-block sysroot.mount + + _loop=0 + while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do + sleep 1 + _loop=$((_loop + 1)) + done + + if ! is_mounted /sysroot; then + derror "Failed to mount rootfs" + return + fi + + ddebug "NEWROOT=$NEWROOT" + dump_fs $NEWROOT +} + +kdump_emergency_shell() +{ + ddebug "Switching to kdump emergency shell..." + + [ -f /etc/profile ] && . /etc/profile + export PS1='kdump:${PWD}# ' + + . /lib/dracut-lib.sh + if [ -f /dracut-state.sh ]; then + . /dracut-state.sh 2>/dev/null + fi + + source_conf /etc/conf.d + + type plymouth >/dev/null 2>&1 && plymouth quit + + source_hook "emergency" + while read _tty rest; do + ( + echo + echo + echo 'Entering kdump emergency mode.' + echo 'Type "journalctl" to view system logs.' + echo 'Type "rdsosreport" to generate a sosreport, you can then' + echo 'save it elsewhere and attach it to a bug report.' + echo + echo + ) > /dev/$_tty + done < /proc/consoles + sh -i -l + /bin/rm -f -- /.console_lock +} + +do_failure_action() +{ + dinfo "Executing failure action $FAILURE_ACTION" + eval $FAILURE_ACTION +} + +do_final_action() +{ + dinfo "Executing final action $FINAL_ACTION" + eval $FINAL_ACTION +} do_dump() { local _ret diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 73b2699..b30b024 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -3,35 +3,9 @@ # Function and variables used in initramfs environment, POSIX compatible # -. /lib/kdump-logger.sh - DEFAULT_PATH="/var/crash/" -KDUMP_PATH="/var/crash" -KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log" -CORE_COLLECTOR="" -DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31" -DMESG_COLLECTOR="/sbin/vmcore-dmesg" -FAILURE_ACTION="systemctl reboot -f" -DATEDIR=`date +%Y-%m-%d-%T` -HOST_IP='127.0.0.1' -DUMP_INSTRUCTION="" -SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" -KDUMP_SCRIPT_DIR="/kdumpscripts" -DD_BLKSIZE=512 -FINAL_ACTION="systemctl reboot -f" -KDUMP_PRE="" -KDUMP_POST="" -NEWROOT="/sysroot" -OPALCORE="/sys/firmware/opal/mpipl/core" KDUMP_CONFIG_FILE="/etc/kdump.conf" -#initiate the kdump logger -dlog_init -if [ $? -ne 0 ]; then - echo "failed to initiate the kdump logger." - exit 1 -fi - # Read kdump config in well formated style kdump_read_conf() { @@ -156,266 +130,3 @@ is_fs_dump_target() { [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix") ]] } - -get_kdump_confs() -{ - local config_opt config_val - - while read config_opt config_val; - do - # remove inline comments after the end of a directive. - case "$config_opt" in - path) - KDUMP_PATH="$config_val" - ;; - core_collector) - [ -n "$config_val" ] && CORE_COLLECTOR="$config_val" - ;; - sshkey) - if [ -f "$config_val" ]; then - SSH_KEY_LOCATION=$config_val - fi - ;; - kdump_pre) - KDUMP_PRE="$config_val" - ;; - kdump_post) - KDUMP_POST="$config_val" - ;; - fence_kdump_args) - FENCE_KDUMP_ARGS="$config_val" - ;; - fence_kdump_nodes) - FENCE_KDUMP_NODES="$config_val" - ;; - failure_action|default) - case $config_val in - shell) - FAILURE_ACTION="kdump_emergency_shell" - ;; - reboot) - FAILURE_ACTION="systemctl reboot -f && exit" - ;; - halt) - FAILURE_ACTION="halt && exit" - ;; - poweroff) - FAILURE_ACTION="systemctl poweroff -f && exit" - ;; - dump_to_rootfs) - FAILURE_ACTION="dump_to_rootfs" - ;; - esac - ;; - final_action) - case $config_val in - reboot) - FINAL_ACTION="systemctl reboot -f" - ;; - halt) - FINAL_ACTION="halt" - ;; - poweroff) - FINAL_ACTION="systemctl poweroff -f" - ;; - esac - ;; - esac - done <<< "$(kdump_read_conf)" - - if [ -z "$CORE_COLLECTOR" ]; then - CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" - if is_ssh_dump_target || is_raw_dump_target; then - CORE_COLLECTOR="$CORE_COLLECTOR -F" - fi - fi -} - -# store the kexec kernel log to a file. -save_log() -{ - dmesg -T > $KDUMP_LOG_FILE - - if command -v journalctl > /dev/null; then - journalctl -ab >> $KDUMP_LOG_FILE - fi - chmod 600 $KDUMP_LOG_FILE -} - -# dump_fs -dump_fs() -{ - local _exitcode - local _mp=$1 - local _op=$(get_mount_info OPTIONS target $_mp -f) - ddebug "dump_fs _mp=$_mp _opts=$_op" - - if ! is_mounted "$_mp"; then - dinfo "dump path \"$_mp\" is not mounted, trying to mount..." - mount --target $_mp - if [ $? -ne 0 ]; then - derror "failed to dump to \"$_mp\", it's not a mount point!" - return 1 - fi - fi - - # Remove -F in makedumpfile case. We don't want a flat format dump here. - [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"` - - local _dump_path=$(echo "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) - - dinfo "saving to $_dump_path" - - # Only remount to read-write mode if the dump target is mounted read-only. - if [[ "$_op" = "ro"* ]]; then - dinfo "Remounting the dump target in rw mode." - mount -o remount,rw $_mp || return 1 - fi - - mkdir -p $_dump_path || return 1 - - save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_path" - save_opalcore_fs "$_dump_path" - - dinfo "saving vmcore" - $CORE_COLLECTOR /proc/vmcore $_dump_path/vmcore-incomplete - _exitcode=$? - if [ $_exitcode -eq 0 ]; then - mv $_dump_path/vmcore-incomplete $_dump_path/vmcore - sync - dinfo "saving vmcore complete" - else - derror "saving vmcore failed, _exitcode:$_exitcode" - fi - - dinfo "saving the $KDUMP_LOG_FILE to $_dump_path/" - save_log - mv $KDUMP_LOG_FILE $_dump_path/ - if [ $_exitcode -ne 0 ]; then - return 1 - fi - - # improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure - return 0 -} - -save_vmcore_dmesg_fs() { - local _dmesg_collector=$1 - local _path=$2 - - dinfo "saving vmcore-dmesg.txt to ${_path}" - $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt - _exitcode=$? - if [ $_exitcode -eq 0 ]; then - mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt - chmod 600 ${_path}/vmcore-dmesg.txt - - # Make sure file is on disk. There have been instances where later - # saving vmcore failed and system rebooted without sync and there - # was no vmcore-dmesg.txt available. - sync - dinfo "saving vmcore-dmesg.txt complete" - else - if [ -f ${_path}/vmcore-dmesg-incomplete.txt ]; then - chmod 600 ${_path}/vmcore-dmesg-incomplete.txt - fi - derror "saving vmcore-dmesg.txt failed" - fi -} - -save_opalcore_fs() { - local _path=$1 - - if [ ! -f $OPALCORE ]; then - # Check if we are on an old kernel that uses a different path - if [ -f /sys/firmware/opal/core ]; then - OPALCORE="/sys/firmware/opal/core" - else - return 0 - fi - fi - - dinfo "saving opalcore:$OPALCORE to ${_path}/opalcore" - cp $OPALCORE ${_path}/opalcore - if [ $? -ne 0 ]; then - derror "saving opalcore failed" - return 1 - fi - - sync - dinfo "saving opalcore complete" - return 0 -} - -dump_to_rootfs() -{ - - if [[ $(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p") == "inactive" ]]; then - dinfo "Trying to bring up initqueue for rootfs mount" - systemctl start dracut-initqueue - fi - - dinfo "Clean up dead systemd services" - systemctl cancel - dinfo "Waiting for rootfs mount, will timeout after 90 seconds" - systemctl start --no-block sysroot.mount - - _loop=0 - while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do - sleep 1 - _loop=$((_loop + 1)) - done - - if ! is_mounted /sysroot; then - derror "Failed to mount rootfs" - return - fi - - ddebug "NEWROOT=$NEWROOT" - dump_fs $NEWROOT -} - -kdump_emergency_shell() -{ - ddebug "Switching to kdump emergency shell..." - - [ -f /etc/profile ] && . /etc/profile - export PS1='kdump:${PWD}# ' - - . /lib/dracut-lib.sh - if [ -f /dracut-state.sh ]; then - . /dracut-state.sh 2>/dev/null - fi - - source_conf /etc/conf.d - - type plymouth >/dev/null 2>&1 && plymouth quit - - source_hook "emergency" - while read _tty rest; do - ( - echo - echo - echo 'Entering kdump emergency mode.' - echo 'Type "journalctl" to view system logs.' - echo 'Type "rdsosreport" to generate a sosreport, you can then' - echo 'save it elsewhere and attach it to a bug report.' - echo - echo - ) > /dev/$_tty - done < /proc/consoles - sh -i -l - /bin/rm -f -- /.console_lock -} - -do_failure_action() -{ - dinfo "Executing failure action $FAILURE_ACTION" - eval $FAILURE_ACTION -} - -do_final_action() -{ - dinfo "Executing final action $FINAL_ACTION" - eval $FINAL_ACTION -} From 0675edbadb2320b8809aa8751b356ccafc78d857 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 2 Aug 2021 01:19:44 +0800 Subject: [PATCH 130/454] dracut-kdump.sh: don't put KDUMP_SCRIPT_DIR in PATH monitor_dd_progress is the only extra binary in KDUMP_SCRIPT_DIR, no need to change PATH environment variable, just call it directly. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index a785ab9..54e9713 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -24,7 +24,6 @@ DATEDIR=`date +%Y-%m-%d-%T` HOST_IP='127.0.0.1' DUMP_INSTRUCTION="" SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" -KDUMP_SCRIPT_DIR="/kdumpscripts" DD_BLKSIZE=512 FINAL_ACTION="systemctl reboot -f" KDUMP_PRE="" @@ -35,8 +34,6 @@ OPALCORE="/sys/firmware/opal/mpipl/core" set -o pipefail DUMP_RETVAL=0 -export PATH=$PATH:$KDUMP_SCRIPT_DIR - get_kdump_confs() { local config_opt config_val @@ -378,7 +375,7 @@ dump_raw() if ! $(echo -n $CORE_COLLECTOR|grep -q makedumpfile); then _src_size=`ls -l /proc/vmcore | cut -d' ' -f5` _src_size_mb=$(($_src_size / 1048576)) - monitor_dd_progress $_src_size_mb & + /kdumpscripts/monitor_dd_progress $_src_size_mb & fi dinfo "saving vmcore" From 8f89e890713c382c88a7e00420ef3b98c2dc708d Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 2 Aug 2021 01:25:17 +0800 Subject: [PATCH 131/454] dracut-kdump.sh: remove add_dump_code `add_dump_code ""` is just `DUMP_INSTRUCTION=""`, no need a extra wrapper for that. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 54e9713..7cfa31b 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -36,9 +36,7 @@ DUMP_RETVAL=0 get_kdump_confs() { - local config_opt config_val - - while read config_opt config_val; + while read -r config_opt config_val; do # remove inline comments after the end of a directive. case "$config_opt" in @@ -359,11 +357,6 @@ do_kdump_post() fi } -add_dump_code() -{ - DUMP_INSTRUCTION=$1 -} - dump_raw() { local _raw=$1 @@ -547,18 +540,18 @@ read_kdump_confs() config_val=$(get_dracut_args_target "$config_val") if [ -n "$config_val" ]; then config_val=$(get_mntpoint_from_target "$config_val") - add_dump_code "dump_fs $config_val" + DUMP_INSTRUCTION="dump_fs $config_val" fi ;; ext[234]|xfs|btrfs|minix|nfs) config_val=$(get_mntpoint_from_target "$config_val") - add_dump_code "dump_fs $config_val" + DUMP_INSTRUCTION="dump_fs $config_val" ;; raw) - add_dump_code "dump_raw $config_val" + DUMP_INSTRUCTION="dump_raw $config_val" ;; ssh) - add_dump_code "dump_ssh $SSH_KEY_LOCATION $config_val" + DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val" ;; esac done <<< "$(kdump_read_conf)" @@ -594,7 +587,7 @@ if [ $? -ne 0 ]; then fi if [ -z "$DUMP_INSTRUCTION" ]; then - add_dump_code "dump_fs $NEWROOT" + DUMP_INSTRUCTION="dump_fs $NEWROOT" fi do_kdump_pre From 7a9823b42e13cb9ff535009f28f89d197b14bbb0 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 3 Aug 2021 13:23:26 +0800 Subject: [PATCH 132/454] dracut-kdump.sh: simplify dump_ssh There is a workaround for `scp` that it expects IPv6 address to be quoted with [ ... ], only apply the workaround once and store the updated `scp` address to reuse it. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 7cfa31b..b92854e 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -387,29 +387,25 @@ dump_ssh() local _dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" local _host=$2 local _vmcore="vmcore" - local _ipv6_addr="" _username="" + + if is_ipv6_address "$_host"; then + _scp_address=${_host%@*}@"[${_host#*@}]" + else + _scp_address=$_host + fi dinfo "saving to $_host:$_dir" cat /var/lib/random-seed > /dev/urandom ssh -q $_opt $_host mkdir -p $_dir || return 1 - save_vmcore_dmesg_ssh ${DMESG_COLLECTOR} ${_dir} "${_opt}" $_host - save_opalcore_ssh ${_dir} "${_opt}" $_host - + save_vmcore_dmesg_ssh ${DMESG_COLLECTOR} ${_dir} "${_opt}" "$_host" dinfo "saving vmcore" - if is_ipv6_address "$_host"; then - _username=${_host%@*} - _ipv6_addr="[${_host#*@}]" - fi + save_opalcore_ssh ${_dir} "${_opt}" "$_host" "$_scp_address" if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then - if [ -n "$_username" ] && [ -n "$_ipv6_addr" ]; then - scp -q $_opt /proc/vmcore "$_username@$_ipv6_addr:$_dir/vmcore-incomplete" - else - scp -q $_opt /proc/vmcore "$_host:$_dir/vmcore-incomplete" - fi + scp -q $_opt /proc/vmcore "$_scp_address:$_dir/vmcore-incomplete" _exitcode=$? else $CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "umask 0077 && dd bs=512 of=$_dir/vmcore-incomplete" @@ -431,11 +427,7 @@ dump_ssh() dinfo "saving the $KDUMP_LOG_FILE to $_host:$_dir/" save_log - if [ -n "$_username" ] && [ -n "$_ipv6_addr" ]; then - scp -q $_opt $KDUMP_LOG_FILE "$_username@$_ipv6_addr:$_dir/" - else - scp -q $_opt $KDUMP_LOG_FILE "$_host:$_dir/" - fi + scp -q $_opt $KDUMP_LOG_FILE "$_scp_address:$_dir/" _ret=$? if [ $_ret -ne 0 ]; then derror "saving log file failed, _exitcode:$_ret" @@ -452,7 +444,7 @@ save_opalcore_ssh() { local _path=$1 local _opts="$2" local _location=$3 - local _user_name="" _ipv6addr="" + local _scp_address=$4 ddebug "_path=$_path _opts=$_opts _location=$_location" @@ -465,18 +457,9 @@ save_opalcore_ssh() { fi fi - if is_ipv6_address "$_host"; then - _user_name=${_location%@*} - _ipv6addr="[${_location#*@}]" - fi - dinfo "saving opalcore:$OPALCORE to $_location:$_path" - if [ -n "$_user_name" ] && [ -n "$_ipv6addr" ]; then - scp $_opts $OPALCORE $_user_name@$_ipv6addr:$_path/opalcore-incomplete - else - scp $_opts $OPALCORE $_location:$_path/opalcore-incomplete - fi + scp $_opts $OPALCORE $_scp_address:$_path/opalcore-incomplete if [ $? -ne 0 ]; then derror "saving opalcore failed" return 1 From b1c794a2cf1a4ed6c8fc2588d1e03ffcde07813c Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 14 Sep 2021 03:00:48 +0800 Subject: [PATCH 133/454] dracut-kdump.sh: Use stat instead of ls to get vmcore size ls output is fragile, so use stat instead. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 2 +- dracut-module-setup.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index b92854e..25972e4 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -366,7 +366,7 @@ dump_raw() dinfo "saving to raw disk $_raw" if ! $(echo -n $CORE_COLLECTOR|grep -q makedumpfile); then - _src_size=`ls -l /proc/vmcore | cut -d' ' -f5` + _src_size=$(stat --format %s /proc/vmcore) _src_size_mb=$(($_src_size / 1048576)) /kdumpscripts/monitor_dd_progress $_src_size_mb & fi diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index d6011ee..80b5582 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1029,6 +1029,7 @@ install() { inst "/bin/head" "/bin/head" inst "/bin/awk" "/bin/awk" inst "/bin/sed" "/bin/sed" + inst "/bin/stat" "/bin/stat" inst "/sbin/makedumpfile" "/sbin/makedumpfile" inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg" inst "/usr/bin/printf" "/sbin/printf" From 725027b735e6f27e51572c570b34c0c7186203ef Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 12 Aug 2021 02:55:32 +0800 Subject: [PATCH 134/454] dracut-kdump.sh: POSIX doesn't support pipefail Set pipefail will cause POSIX shell to exit with failure. So only do that in bash. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 25972e4..3c1b080 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -31,7 +31,10 @@ KDUMP_POST="" NEWROOT="/sysroot" OPALCORE="/sys/firmware/opal/mpipl/core" -set -o pipefail +# POSIX doesn't have pipefail, only apply when using bash +# shellcheck disable=SC3040 +[ -n "$BASH" ] && set -o pipefail + DUMP_RETVAL=0 get_kdump_confs() From b1339c3b8a006f95d8414c6e113fbec78bc03123 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 18 Aug 2021 21:06:52 +0800 Subject: [PATCH 135/454] dracut-kdump.sh: make it POSIX compatible POSIX doesn't support keyword `local`, so this commit reduced variable usage. Heredoc ("<<<") operation is also not supported, so kdump.conf is now pre-parse into a temp file. Also fixes many POSIX syntax errors. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 260 ++++++++++++++++++++++-------------------------- 1 file changed, 121 insertions(+), 139 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 3c1b080..5cd7ad4 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -8,8 +8,7 @@ . /lib/kdump-lib-initramfs.sh #initiate the kdump logger -dlog_init -if [ $? -ne 0 ]; then +if ! dlog_init; then echo "failed to initiate the kdump logger." exit 1 fi @@ -20,7 +19,7 @@ CORE_COLLECTOR="" DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31" DMESG_COLLECTOR="/sbin/vmcore-dmesg" FAILURE_ACTION="systemctl reboot -f" -DATEDIR=`date +%Y-%m-%d-%T` +DATEDIR=$(date +%Y-%m-%d-%T) HOST_IP='127.0.0.1' DUMP_INSTRUCTION="" SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" @@ -30,6 +29,7 @@ KDUMP_PRE="" KDUMP_POST="" NEWROOT="/sysroot" OPALCORE="/sys/firmware/opal/mpipl/core" +KDUMP_CONF_PARSED="/tmp/kdump.conf.$$" # POSIX doesn't have pipefail, only apply when using bash # shellcheck disable=SC3040 @@ -37,10 +37,11 @@ OPALCORE="/sys/firmware/opal/mpipl/core" DUMP_RETVAL=0 +kdump_read_conf > $KDUMP_CONF_PARSED + get_kdump_confs() { - while read -r config_opt config_val; - do + while read -r config_opt config_val; do # remove inline comments after the end of a directive. case "$config_opt" in path) @@ -99,7 +100,7 @@ get_kdump_confs() esac ;; esac - done <<< "$(kdump_read_conf)" + done < "$KDUMP_CONF_PARSED" if [ -z "$CORE_COLLECTOR" ]; then CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" @@ -120,56 +121,58 @@ save_log() chmod 600 $KDUMP_LOG_FILE } -# dump_fs +# $1: dump path, must be a mount point dump_fs() { - local _exitcode - local _mp=$1 - local _op=$(get_mount_info OPTIONS target $_mp -f) - ddebug "dump_fs _mp=$_mp _opts=$_op" + ddebug "dump_fs _mp=$1" - if ! is_mounted "$_mp"; then - dinfo "dump path \"$_mp\" is not mounted, trying to mount..." - mount --target $_mp - if [ $? -ne 0 ]; then - derror "failed to dump to \"$_mp\", it's not a mount point!" + if ! is_mounted "$1"; then + dinfo "dump path '$1' is not mounted, trying to mount..." + if ! mount --target "$1"; then + derror "failed to dump to '$1', it's not a mount point!" return 1 fi fi # Remove -F in makedumpfile case. We don't want a flat format dump here. - [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"` + case $CORE_COLLECTOR in + *makedumpfile* ) + CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g") + ;; + esac - local _dump_path=$(echo "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) - - dinfo "saving to $_dump_path" + _dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) + dinfo "saving to $_dump_fs_path" # Only remount to read-write mode if the dump target is mounted read-only. - if [[ "$_op" = "ro"* ]]; then - dinfo "Remounting the dump target in rw mode." - mount -o remount,rw $_mp || return 1 - fi + _dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f) + case $_dump_mnt_op in + ro* ) + dinfo "Remounting the dump target in rw mode." + mount -o remount,rw "$1" || return 1 + ;; + esac - mkdir -p $_dump_path || return 1 + mkdir -p "$_dump_fs_path" || return 1 - save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_path" - save_opalcore_fs "$_dump_path" + save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path" + save_opalcore_fs "$_dump_fs_path" dinfo "saving vmcore" - $CORE_COLLECTOR /proc/vmcore $_dump_path/vmcore-incomplete - _exitcode=$? - if [ $_exitcode -eq 0 ]; then - mv $_dump_path/vmcore-incomplete $_dump_path/vmcore + $CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete" + _dump_exitcode=$? + if [ $_dump_exitcode -eq 0 ]; then + mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore" sync dinfo "saving vmcore complete" else - derror "saving vmcore failed, _exitcode:$_exitcode" + derror "saving vmcore failed, exitcode:$_dump_exitcode" fi - dinfo "saving the $KDUMP_LOG_FILE to $_dump_path/" + dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/" save_log - mv $KDUMP_LOG_FILE $_dump_path/ - if [ $_exitcode -ne 0 ]; then + mv "$KDUMP_LOG_FILE" "$_dump_fs_path/" + if [ $_dump_exitcode -ne 0 ]; then return 1 fi @@ -177,16 +180,13 @@ dump_fs() return 0 } +# $1: dmesg collector +# $2: dump path save_vmcore_dmesg_fs() { - local _dmesg_collector=$1 - local _path=$2 - - dinfo "saving vmcore-dmesg.txt to ${_path}" - $_dmesg_collector /proc/vmcore > ${_path}/vmcore-dmesg-incomplete.txt - _exitcode=$? - if [ $_exitcode -eq 0 ]; then - mv ${_path}/vmcore-dmesg-incomplete.txt ${_path}/vmcore-dmesg.txt - chmod 600 ${_path}/vmcore-dmesg.txt + dinfo "saving vmcore-dmesg.txt to $2" + if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then + mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" + chmod 600 "$2/vmcore-dmesg.txt" # Make sure file is on disk. There have been instances where later # saving vmcore failed and system rebooted without sync and there @@ -194,16 +194,15 @@ save_vmcore_dmesg_fs() { sync dinfo "saving vmcore-dmesg.txt complete" else - if [ -f ${_path}/vmcore-dmesg-incomplete.txt ]; then - chmod 600 ${_path}/vmcore-dmesg-incomplete.txt + if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then + chmod 600 "$2/vmcore-dmesg-incomplete.txt" fi derror "saving vmcore-dmesg.txt failed" fi } +# $1: dump path save_opalcore_fs() { - local _path=$1 - if [ ! -f $OPALCORE ]; then # Check if we are on an old kernel that uses a different path if [ -f /sys/firmware/opal/core ]; then @@ -213,9 +212,8 @@ save_opalcore_fs() { fi fi - dinfo "saving opalcore:$OPALCORE to ${_path}/opalcore" - cp $OPALCORE ${_path}/opalcore - if [ $? -ne 0 ]; then + dinfo "saving opalcore:$OPALCORE to $1/opalcore" + if ! cp $OPALCORE "$1/opalcore"; then derror "saving opalcore failed" return 1 fi @@ -228,7 +226,7 @@ save_opalcore_fs() { dump_to_rootfs() { - if [[ $(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p") == "inactive" ]]; then + if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then dinfo "Trying to bring up initqueue for rootfs mount" systemctl start dracut-initqueue fi @@ -270,7 +268,7 @@ kdump_emergency_shell() type plymouth >/dev/null 2>&1 && plymouth quit source_hook "emergency" - while read _tty rest; do + while read -r _tty rest; do ( echo echo @@ -280,7 +278,7 @@ kdump_emergency_shell() echo 'save it elsewhere and attach it to a bug report.' echo echo - ) > /dev/$_tty + ) > "/dev/$_tty" done < /proc/consoles sh -i -l /bin/rm -f -- /.console_lock @@ -297,10 +295,9 @@ do_final_action() dinfo "Executing final action $FINAL_ACTION" eval $FINAL_ACTION } + do_dump() { - local _ret - eval $DUMP_INSTRUCTION _ret=$? @@ -313,8 +310,6 @@ do_dump() do_kdump_pre() { - local _ret - if [ -n "$KDUMP_PRE" ]; then "$KDUMP_PRE" _ret=$? @@ -339,8 +334,6 @@ do_kdump_pre() do_kdump_post() { - local _ret - if [ -d /etc/kdump/post.d ]; then for file in /etc/kdump/post.d/*; do "$file" "$1" @@ -360,97 +353,86 @@ do_kdump_post() fi } +# $1: block target, eg. /dev/sda dump_raw() { - local _raw=$1 + [ -b "$1" ] || return 1 - [ -b "$_raw" ] || return 1 + dinfo "saving to raw disk $1" - dinfo "saving to raw disk $_raw" - - if ! $(echo -n $CORE_COLLECTOR|grep -q makedumpfile); then + if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then _src_size=$(stat --format %s /proc/vmcore) - _src_size_mb=$(($_src_size / 1048576)) + _src_size_mb=$((_src_size / 1048576)) /kdumpscripts/monitor_dd_progress $_src_size_mb & fi dinfo "saving vmcore" - $CORE_COLLECTOR /proc/vmcore | dd of=$_raw bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1 + $CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1 sync dinfo "saving vmcore complete" return 0 } +# $1: ssh key file +# $2: ssh address in @ format dump_ssh() { - local _ret=0 - local _exitcode=0 _exitcode2=0 - local _opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes" - local _dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" - local _host=$2 - local _vmcore="vmcore" - - if is_ipv6_address "$_host"; then - _scp_address=${_host%@*}@"[${_host#*@}]" + _ret=0 + _ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes" + _ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" + if is_ipv6_address "$2"; then + _scp_address=${2%@*}@"[${2#*@}]" else - _scp_address=$_host + _scp_address=$2 fi - dinfo "saving to $_host:$_dir" + dinfo "saving to $2:$_ssh_dir" cat /var/lib/random-seed > /dev/urandom - ssh -q $_opt $_host mkdir -p $_dir || return 1 + ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1 - save_vmcore_dmesg_ssh ${DMESG_COLLECTOR} ${_dir} "${_opt}" "$_host" + save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2" dinfo "saving vmcore" - save_opalcore_ssh ${_dir} "${_opt}" "$_host" "$_scp_address" + save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address" if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then - scp -q $_opt /proc/vmcore "$_scp_address:$_dir/vmcore-incomplete" - _exitcode=$? + scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete" + _ret=$? + _vmcore="vmcore" else - $CORE_COLLECTOR /proc/vmcore | ssh $_opt $_host "umask 0077 && dd bs=512 of=$_dir/vmcore-incomplete" - _exitcode=$? + $CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'" + _ret=$? _vmcore="vmcore.flat" fi - if [ $_exitcode -eq 0 ]; then - ssh $_opt $_host "mv $_dir/vmcore-incomplete $_dir/$_vmcore" - _exitcode2=$? - if [ $_exitcode2 -ne 0 ]; then - derror "moving vmcore failed, _exitcode:$_exitcode2" + if [ $_ret -eq 0 ]; then + ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "moving vmcore failed, exitcode:$_ret" else dinfo "saving vmcore complete" fi else - derror "saving vmcore failed, _exitcode:$_exitcode" + derror "saving vmcore failed, exitcode:$_ret" fi - dinfo "saving the $KDUMP_LOG_FILE to $_host:$_dir/" + dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/" save_log - scp -q $_opt $KDUMP_LOG_FILE "$_scp_address:$_dir/" - _ret=$? - if [ $_ret -ne 0 ]; then + if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then derror "saving log file failed, _exitcode:$_ret" fi - if [ $_exitcode -ne 0 ] || [ $_exitcode2 -ne 0 ];then - return 1 - fi - - return 0 + return $_ret } +# $1: dump path +# $2: ssh opts +# $3: ssh address in @ format +# $4: scp address, similar with ssh address but IPv6 addresses are quoted save_opalcore_ssh() { - local _path=$1 - local _opts="$2" - local _location=$3 - local _scp_address=$4 - - ddebug "_path=$_path _opts=$_opts _location=$_location" - if [ ! -f $OPALCORE ]; then # Check if we are on an old kernel that uses a different path if [ -f /sys/firmware/opal/core ]; then @@ -460,31 +442,26 @@ save_opalcore_ssh() { fi fi - dinfo "saving opalcore:$OPALCORE to $_location:$_path" + dinfo "saving opalcore:$OPALCORE to $3:$1" - scp $_opts $OPALCORE $_scp_address:$_path/opalcore-incomplete - if [ $? -ne 0 ]; then + if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then derror "saving opalcore failed" - return 1 + return 1 fi - ssh $_opts $_location mv $_path/opalcore-incomplete $_path/opalcore + ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore" dinfo "saving opalcore complete" return 0 } +# $1: dmesg collector +# $2: dump path +# $3: ssh opts +# $4: ssh address in @ format save_vmcore_dmesg_ssh() { - local _dmesg_collector=$1 - local _path=$2 - local _opts="$3" - local _location=$4 - - dinfo "saving vmcore-dmesg.txt to $_location:$_path" - $_dmesg_collector /proc/vmcore | ssh $_opts $_location "umask 0077 && dd of=$_path/vmcore-dmesg-incomplete.txt" - _exitcode=$? - - if [ $_exitcode -eq 0 ]; then - ssh -q $_opts $_location mv $_path/vmcore-dmesg-incomplete.txt $_path/vmcore-dmesg.txt + dinfo "saving vmcore-dmesg.txt to $4:$2" + if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then + ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" dinfo "saving vmcore-dmesg.txt complete" else derror "saving vmcore-dmesg.txt failed" @@ -493,17 +470,24 @@ save_vmcore_dmesg_ssh() { get_host_ip() { - local _host if is_nfs_dump_target || is_ssh_dump_target then kdumpnic=$(getarg kdumpnic=) - [ -z "$kdumpnic" ] && derror "failed to get kdumpnic!" && return 1 - _host=`ip addr show dev $kdumpnic|grep '[ ]*inet'` - [ $? -ne 0 ] && derror "wrong kdumpnic: $kdumpnic" && return 1 - _host=`echo $_host | head -n 1 | cut -d' ' -f2` - _host="${_host%%/*}" - [ -z "$_host" ] && derror "wrong kdumpnic: $kdumpnic" && return 1 - HOST_IP=$_host + if [ -z "$kdumpnic" ]; then + derror "failed to get kdumpnic!" + return 1 + fi + if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then + derror "wrong kdumpnic: $kdumpnic" + return 1 + fi + kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}') + kdumphost="${kdumphost%%/*}" + if [ -z "$kdumphost" ]; then + derror "wrong kdumpnic: $kdumpnic" + return 1 + fi + HOST_IP=$kdumphost fi return 0 } @@ -518,7 +502,7 @@ read_kdump_confs() get_kdump_confs # rescan for add code for dump target - while read config_opt config_val; + while read -r config_opt config_val; do # remove inline comments after the end of a directive. case "$config_opt" in @@ -540,12 +524,13 @@ read_kdump_confs() DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val" ;; esac - done <<< "$(kdump_read_conf)" + done < "$KDUMP_CONF_PARSED" } fence_kdump_notify() { if [ -n "$FENCE_KDUMP_NODES" ]; then + # shellcheck disable=SC2086 $FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES & fi } @@ -566,8 +551,7 @@ fi read_kdump_confs fence_kdump_notify -get_host_ip -if [ $? -ne 0 ]; then +if ! get_host_ip; then derror "get_host_ip exited with non-zero status!" exit 1 fi @@ -576,8 +560,7 @@ if [ -z "$DUMP_INSTRUCTION" ]; then DUMP_INSTRUCTION="dump_fs $NEWROOT" fi -do_kdump_pre -if [ $? -ne 0 ]; then +if ! do_kdump_pre; then derror "kdump_pre script exited with non-zero status!" do_final_action # During systemd service to reboot the machine, stop this shell script running @@ -587,8 +570,7 @@ make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab' do_dump DUMP_RETVAL=$? -do_kdump_post $DUMP_RETVAL -if [ $? -ne 0 ]; then +if ! do_kdump_post $DUMP_RETVAL; then derror "kdump_post script exited with non-zero status!" fi From 7c76611abba248e58172fdf170739a3c0f40e2c6 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 15 Sep 2021 23:10:07 +0800 Subject: [PATCH 136/454] dracut-kdump.sh: reformat with shfmt This is done with `shfmt -w -s dracut-kdump.sh`. There is no behaviour change. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 768 ++++++++++++++++++++++++------------------------ 1 file changed, 385 insertions(+), 383 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 5cd7ad4..969ea94 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -9,8 +9,8 @@ #initiate the kdump logger if ! dlog_init; then - echo "failed to initiate the kdump logger." - exit 1 + echo "failed to initiate the kdump logger." + exit 1 fi KDUMP_PATH="/var/crash" @@ -41,541 +41,543 @@ kdump_read_conf > $KDUMP_CONF_PARSED get_kdump_confs() { - while read -r config_opt config_val; do - # remove inline comments after the end of a directive. - case "$config_opt" in - path) - KDUMP_PATH="$config_val" - ;; - core_collector) - [ -n "$config_val" ] && CORE_COLLECTOR="$config_val" - ;; - sshkey) - if [ -f "$config_val" ]; then - SSH_KEY_LOCATION=$config_val - fi - ;; - kdump_pre) - KDUMP_PRE="$config_val" - ;; - kdump_post) - KDUMP_POST="$config_val" - ;; - fence_kdump_args) - FENCE_KDUMP_ARGS="$config_val" - ;; - fence_kdump_nodes) - FENCE_KDUMP_NODES="$config_val" - ;; - failure_action|default) - case $config_val in - shell) - FAILURE_ACTION="kdump_emergency_shell" - ;; - reboot) - FAILURE_ACTION="systemctl reboot -f && exit" - ;; - halt) - FAILURE_ACTION="halt && exit" - ;; - poweroff) - FAILURE_ACTION="systemctl poweroff -f && exit" - ;; - dump_to_rootfs) - FAILURE_ACTION="dump_to_rootfs" - ;; - esac - ;; - final_action) - case $config_val in - reboot) - FINAL_ACTION="systemctl reboot -f" - ;; - halt) - FINAL_ACTION="halt" - ;; - poweroff) - FINAL_ACTION="systemctl poweroff -f" - ;; - esac - ;; - esac - done < "$KDUMP_CONF_PARSED" + while read -r config_opt config_val; do + # remove inline comments after the end of a directive. + case "$config_opt" in + path) + KDUMP_PATH="$config_val" + ;; + core_collector) + [ -n "$config_val" ] && CORE_COLLECTOR="$config_val" + ;; + sshkey) + if [ -f "$config_val" ]; then + SSH_KEY_LOCATION=$config_val + fi + ;; + kdump_pre) + KDUMP_PRE="$config_val" + ;; + kdump_post) + KDUMP_POST="$config_val" + ;; + fence_kdump_args) + FENCE_KDUMP_ARGS="$config_val" + ;; + fence_kdump_nodes) + FENCE_KDUMP_NODES="$config_val" + ;; + failure_action | default) + case $config_val in + shell) + FAILURE_ACTION="kdump_emergency_shell" + ;; + reboot) + FAILURE_ACTION="systemctl reboot -f && exit" + ;; + halt) + FAILURE_ACTION="halt && exit" + ;; + poweroff) + FAILURE_ACTION="systemctl poweroff -f && exit" + ;; + dump_to_rootfs) + FAILURE_ACTION="dump_to_rootfs" + ;; + esac + ;; + final_action) + case $config_val in + reboot) + FINAL_ACTION="systemctl reboot -f" + ;; + halt) + FINAL_ACTION="halt" + ;; + poweroff) + FINAL_ACTION="systemctl poweroff -f" + ;; + esac + ;; + esac + done < "$KDUMP_CONF_PARSED" - if [ -z "$CORE_COLLECTOR" ]; then - CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" - if is_ssh_dump_target || is_raw_dump_target; then - CORE_COLLECTOR="$CORE_COLLECTOR -F" - fi - fi + if [ -z "$CORE_COLLECTOR" ]; then + CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" + if is_ssh_dump_target || is_raw_dump_target; then + CORE_COLLECTOR="$CORE_COLLECTOR -F" + fi + fi } # store the kexec kernel log to a file. save_log() { - dmesg -T > $KDUMP_LOG_FILE + dmesg -T > $KDUMP_LOG_FILE - if command -v journalctl > /dev/null; then - journalctl -ab >> $KDUMP_LOG_FILE - fi - chmod 600 $KDUMP_LOG_FILE + if command -v journalctl > /dev/null; then + journalctl -ab >> $KDUMP_LOG_FILE + fi + chmod 600 $KDUMP_LOG_FILE } # $1: dump path, must be a mount point dump_fs() { - ddebug "dump_fs _mp=$1" + ddebug "dump_fs _mp=$1" - if ! is_mounted "$1"; then - dinfo "dump path '$1' is not mounted, trying to mount..." - if ! mount --target "$1"; then - derror "failed to dump to '$1', it's not a mount point!" - return 1 - fi - fi + if ! is_mounted "$1"; then + dinfo "dump path '$1' is not mounted, trying to mount..." + if ! mount --target "$1"; then + derror "failed to dump to '$1', it's not a mount point!" + return 1 + fi + fi - # Remove -F in makedumpfile case. We don't want a flat format dump here. - case $CORE_COLLECTOR in - *makedumpfile* ) - CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g") - ;; - esac + # Remove -F in makedumpfile case. We don't want a flat format dump here. + case $CORE_COLLECTOR in + *makedumpfile*) + CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g") + ;; + esac - _dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) - dinfo "saving to $_dump_fs_path" + _dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) + dinfo "saving to $_dump_fs_path" - # Only remount to read-write mode if the dump target is mounted read-only. - _dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f) - case $_dump_mnt_op in - ro* ) - dinfo "Remounting the dump target in rw mode." - mount -o remount,rw "$1" || return 1 - ;; - esac + # Only remount to read-write mode if the dump target is mounted read-only. + _dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f) + case $_dump_mnt_op in + ro*) + dinfo "Remounting the dump target in rw mode." + mount -o remount,rw "$1" || return 1 + ;; + esac - mkdir -p "$_dump_fs_path" || return 1 + mkdir -p "$_dump_fs_path" || return 1 - save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path" - save_opalcore_fs "$_dump_fs_path" + save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path" + save_opalcore_fs "$_dump_fs_path" - dinfo "saving vmcore" - $CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete" - _dump_exitcode=$? - if [ $_dump_exitcode -eq 0 ]; then - mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore" - sync - dinfo "saving vmcore complete" - else - derror "saving vmcore failed, exitcode:$_dump_exitcode" - fi + dinfo "saving vmcore" + $CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete" + _dump_exitcode=$? + if [ $_dump_exitcode -eq 0 ]; then + mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore" + sync + dinfo "saving vmcore complete" + else + derror "saving vmcore failed, exitcode:$_dump_exitcode" + fi - dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/" - save_log - mv "$KDUMP_LOG_FILE" "$_dump_fs_path/" - if [ $_dump_exitcode -ne 0 ]; then - return 1 - fi + dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/" + save_log + mv "$KDUMP_LOG_FILE" "$_dump_fs_path/" + if [ $_dump_exitcode -ne 0 ]; then + return 1 + fi - # improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure - return 0 + # improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure + return 0 } # $1: dmesg collector # $2: dump path -save_vmcore_dmesg_fs() { - dinfo "saving vmcore-dmesg.txt to $2" - if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then - mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" - chmod 600 "$2/vmcore-dmesg.txt" +save_vmcore_dmesg_fs() +{ + dinfo "saving vmcore-dmesg.txt to $2" + if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then + mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" + chmod 600 "$2/vmcore-dmesg.txt" - # Make sure file is on disk. There have been instances where later - # saving vmcore failed and system rebooted without sync and there - # was no vmcore-dmesg.txt available. - sync - dinfo "saving vmcore-dmesg.txt complete" - else - if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then - chmod 600 "$2/vmcore-dmesg-incomplete.txt" - fi - derror "saving vmcore-dmesg.txt failed" - fi + # Make sure file is on disk. There have been instances where later + # saving vmcore failed and system rebooted without sync and there + # was no vmcore-dmesg.txt available. + sync + dinfo "saving vmcore-dmesg.txt complete" + else + if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then + chmod 600 "$2/vmcore-dmesg-incomplete.txt" + fi + derror "saving vmcore-dmesg.txt failed" + fi } # $1: dump path -save_opalcore_fs() { - if [ ! -f $OPALCORE ]; then - # Check if we are on an old kernel that uses a different path - if [ -f /sys/firmware/opal/core ]; then - OPALCORE="/sys/firmware/opal/core" - else - return 0 - fi - fi +save_opalcore_fs() +{ + if [ ! -f $OPALCORE ]; then + # Check if we are on an old kernel that uses a different path + if [ -f /sys/firmware/opal/core ]; then + OPALCORE="/sys/firmware/opal/core" + else + return 0 + fi + fi - dinfo "saving opalcore:$OPALCORE to $1/opalcore" - if ! cp $OPALCORE "$1/opalcore"; then - derror "saving opalcore failed" - return 1 - fi + dinfo "saving opalcore:$OPALCORE to $1/opalcore" + if ! cp $OPALCORE "$1/opalcore"; then + derror "saving opalcore failed" + return 1 + fi - sync - dinfo "saving opalcore complete" - return 0 + sync + dinfo "saving opalcore complete" + return 0 } dump_to_rootfs() { - if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then - dinfo "Trying to bring up initqueue for rootfs mount" - systemctl start dracut-initqueue - fi + if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then + dinfo "Trying to bring up initqueue for rootfs mount" + systemctl start dracut-initqueue + fi - dinfo "Clean up dead systemd services" - systemctl cancel - dinfo "Waiting for rootfs mount, will timeout after 90 seconds" - systemctl start --no-block sysroot.mount + dinfo "Clean up dead systemd services" + systemctl cancel + dinfo "Waiting for rootfs mount, will timeout after 90 seconds" + systemctl start --no-block sysroot.mount - _loop=0 - while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do - sleep 1 - _loop=$((_loop + 1)) - done + _loop=0 + while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do + sleep 1 + _loop=$((_loop + 1)) + done - if ! is_mounted /sysroot; then - derror "Failed to mount rootfs" - return - fi + if ! is_mounted /sysroot; then + derror "Failed to mount rootfs" + return + fi - ddebug "NEWROOT=$NEWROOT" - dump_fs $NEWROOT + ddebug "NEWROOT=$NEWROOT" + dump_fs $NEWROOT } kdump_emergency_shell() { - ddebug "Switching to kdump emergency shell..." + ddebug "Switching to kdump emergency shell..." - [ -f /etc/profile ] && . /etc/profile - export PS1='kdump:${PWD}# ' + [ -f /etc/profile ] && . /etc/profile + export PS1='kdump:${PWD}# ' - . /lib/dracut-lib.sh - if [ -f /dracut-state.sh ]; then - . /dracut-state.sh 2>/dev/null - fi + . /lib/dracut-lib.sh + if [ -f /dracut-state.sh ]; then + . /dracut-state.sh 2> /dev/null + fi - source_conf /etc/conf.d + source_conf /etc/conf.d - type plymouth >/dev/null 2>&1 && plymouth quit + type plymouth > /dev/null 2>&1 && plymouth quit - source_hook "emergency" - while read -r _tty rest; do - ( - echo - echo - echo 'Entering kdump emergency mode.' - echo 'Type "journalctl" to view system logs.' - echo 'Type "rdsosreport" to generate a sosreport, you can then' - echo 'save it elsewhere and attach it to a bug report.' - echo - echo - ) > "/dev/$_tty" - done < /proc/consoles - sh -i -l - /bin/rm -f -- /.console_lock + source_hook "emergency" + while read -r _tty rest; do + ( + echo + echo + echo 'Entering kdump emergency mode.' + echo 'Type "journalctl" to view system logs.' + echo 'Type "rdsosreport" to generate a sosreport, you can then' + echo 'save it elsewhere and attach it to a bug report.' + echo + echo + ) > "/dev/$_tty" + done < /proc/consoles + sh -i -l + /bin/rm -f -- /.console_lock } do_failure_action() { - dinfo "Executing failure action $FAILURE_ACTION" - eval $FAILURE_ACTION + dinfo "Executing failure action $FAILURE_ACTION" + eval $FAILURE_ACTION } do_final_action() { - dinfo "Executing final action $FINAL_ACTION" - eval $FINAL_ACTION + dinfo "Executing final action $FINAL_ACTION" + eval $FINAL_ACTION } do_dump() { - eval $DUMP_INSTRUCTION - _ret=$? + eval $DUMP_INSTRUCTION + _ret=$? - if [ $_ret -ne 0 ]; then - derror "saving vmcore failed" - fi + if [ $_ret -ne 0 ]; then + derror "saving vmcore failed" + fi - return $_ret + return $_ret } do_kdump_pre() { - if [ -n "$KDUMP_PRE" ]; then - "$KDUMP_PRE" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$KDUMP_PRE exited with $_ret status" - return $_ret - fi - fi + if [ -n "$KDUMP_PRE" ]; then + "$KDUMP_PRE" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$KDUMP_PRE exited with $_ret status" + return $_ret + fi + fi - # if any script fails, it just raises warning and continues - if [ -d /etc/kdump/pre.d ]; then - for file in /etc/kdump/pre.d/*; do - "$file" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$file exited with $_ret status" - fi - done - fi - return 0 + # if any script fails, it just raises warning and continues + if [ -d /etc/kdump/pre.d ]; then + for file in /etc/kdump/pre.d/*; do + "$file" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$file exited with $_ret status" + fi + done + fi + return 0 } do_kdump_post() { - if [ -d /etc/kdump/post.d ]; then - for file in /etc/kdump/post.d/*; do - "$file" "$1" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$file exited with $_ret status" - fi - done - fi + if [ -d /etc/kdump/post.d ]; then + for file in /etc/kdump/post.d/*; do + "$file" "$1" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$file exited with $_ret status" + fi + done + fi - if [ -n "$KDUMP_POST" ]; then - "$KDUMP_POST" "$1" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$KDUMP_POST exited with $_ret status" - fi - fi + if [ -n "$KDUMP_POST" ]; then + "$KDUMP_POST" "$1" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "$KDUMP_POST exited with $_ret status" + fi + fi } # $1: block target, eg. /dev/sda dump_raw() { - [ -b "$1" ] || return 1 + [ -b "$1" ] || return 1 - dinfo "saving to raw disk $1" + dinfo "saving to raw disk $1" - if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then - _src_size=$(stat --format %s /proc/vmcore) - _src_size_mb=$((_src_size / 1048576)) - /kdumpscripts/monitor_dd_progress $_src_size_mb & - fi + if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then + _src_size=$(stat --format %s /proc/vmcore) + _src_size_mb=$((_src_size / 1048576)) + /kdumpscripts/monitor_dd_progress $_src_size_mb & + fi - dinfo "saving vmcore" - $CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1 - sync + dinfo "saving vmcore" + $CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1 + sync - dinfo "saving vmcore complete" - return 0 + dinfo "saving vmcore complete" + return 0 } # $1: ssh key file # $2: ssh address in @ format dump_ssh() { - _ret=0 - _ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes" - _ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" - if is_ipv6_address "$2"; then - _scp_address=${2%@*}@"[${2#*@}]" - else - _scp_address=$2 - fi + _ret=0 + _ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes" + _ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" + if is_ipv6_address "$2"; then + _scp_address=${2%@*}@"[${2#*@}]" + else + _scp_address=$2 + fi - dinfo "saving to $2:$_ssh_dir" + dinfo "saving to $2:$_ssh_dir" - cat /var/lib/random-seed > /dev/urandom - ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1 + cat /var/lib/random-seed > /dev/urandom + ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1 - save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2" - dinfo "saving vmcore" + save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2" + dinfo "saving vmcore" - save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address" + save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address" - if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then - scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete" - _ret=$? - _vmcore="vmcore" - else - $CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'" - _ret=$? - _vmcore="vmcore.flat" - fi + if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then + scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete" + _ret=$? + _vmcore="vmcore" + else + $CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'" + _ret=$? + _vmcore="vmcore.flat" + fi - if [ $_ret -eq 0 ]; then - ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "moving vmcore failed, exitcode:$_ret" - else - dinfo "saving vmcore complete" - fi - else - derror "saving vmcore failed, exitcode:$_ret" - fi + if [ $_ret -eq 0 ]; then + ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'" + _ret=$? + if [ $_ret -ne 0 ]; then + derror "moving vmcore failed, exitcode:$_ret" + else + dinfo "saving vmcore complete" + fi + else + derror "saving vmcore failed, exitcode:$_ret" + fi - dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/" - save_log - if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then - derror "saving log file failed, _exitcode:$_ret" - fi + dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/" + save_log + if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then + derror "saving log file failed, _exitcode:$_ret" + fi - return $_ret + return $_ret } # $1: dump path # $2: ssh opts # $3: ssh address in @ format # $4: scp address, similar with ssh address but IPv6 addresses are quoted -save_opalcore_ssh() { - if [ ! -f $OPALCORE ]; then - # Check if we are on an old kernel that uses a different path - if [ -f /sys/firmware/opal/core ]; then - OPALCORE="/sys/firmware/opal/core" - else - return 0 - fi - fi +save_opalcore_ssh() +{ + if [ ! -f $OPALCORE ]; then + # Check if we are on an old kernel that uses a different path + if [ -f /sys/firmware/opal/core ]; then + OPALCORE="/sys/firmware/opal/core" + else + return 0 + fi + fi - dinfo "saving opalcore:$OPALCORE to $3:$1" + dinfo "saving opalcore:$OPALCORE to $3:$1" - if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then - derror "saving opalcore failed" - return 1 - fi + if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then + derror "saving opalcore failed" + return 1 + fi - ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore" - dinfo "saving opalcore complete" - return 0 + ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore" + dinfo "saving opalcore complete" + return 0 } # $1: dmesg collector # $2: dump path # $3: ssh opts # $4: ssh address in @ format -save_vmcore_dmesg_ssh() { - dinfo "saving vmcore-dmesg.txt to $4:$2" - if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then - ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" - dinfo "saving vmcore-dmesg.txt complete" - else - derror "saving vmcore-dmesg.txt failed" - fi +save_vmcore_dmesg_ssh() +{ + dinfo "saving vmcore-dmesg.txt to $4:$2" + if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then + ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" + dinfo "saving vmcore-dmesg.txt complete" + else + derror "saving vmcore-dmesg.txt failed" + fi } get_host_ip() { - if is_nfs_dump_target || is_ssh_dump_target - then - kdumpnic=$(getarg kdumpnic=) - if [ -z "$kdumpnic" ]; then - derror "failed to get kdumpnic!" - return 1 - fi - if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then - derror "wrong kdumpnic: $kdumpnic" - return 1 - fi - kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}') - kdumphost="${kdumphost%%/*}" - if [ -z "$kdumphost" ]; then - derror "wrong kdumpnic: $kdumpnic" - return 1 - fi - HOST_IP=$kdumphost - fi - return 0 + if is_nfs_dump_target || is_ssh_dump_target; then + kdumpnic=$(getarg kdumpnic=) + if [ -z "$kdumpnic" ]; then + derror "failed to get kdumpnic!" + return 1 + fi + if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then + derror "wrong kdumpnic: $kdumpnic" + return 1 + fi + kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}') + kdumphost="${kdumphost%%/*}" + if [ -z "$kdumphost" ]; then + derror "wrong kdumpnic: $kdumpnic" + return 1 + fi + HOST_IP=$kdumphost + fi + return 0 } read_kdump_confs() { - if [ ! -f "$KDUMP_CONFIG_FILE" ]; then - derror "$KDUMP_CONFIG_FILE not found" - return - fi + if [ ! -f "$KDUMP_CONFIG_FILE" ]; then + derror "$KDUMP_CONFIG_FILE not found" + return + fi - get_kdump_confs + get_kdump_confs - # rescan for add code for dump target - while read -r config_opt config_val; - do - # remove inline comments after the end of a directive. - case "$config_opt" in - dracut_args) - config_val=$(get_dracut_args_target "$config_val") - if [ -n "$config_val" ]; then - config_val=$(get_mntpoint_from_target "$config_val") - DUMP_INSTRUCTION="dump_fs $config_val" - fi - ;; - ext[234]|xfs|btrfs|minix|nfs) - config_val=$(get_mntpoint_from_target "$config_val") - DUMP_INSTRUCTION="dump_fs $config_val" - ;; - raw) - DUMP_INSTRUCTION="dump_raw $config_val" - ;; - ssh) - DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val" - ;; - esac - done < "$KDUMP_CONF_PARSED" + # rescan for add code for dump target + while read -r config_opt config_val; do + # remove inline comments after the end of a directive. + case "$config_opt" in + dracut_args) + config_val=$(get_dracut_args_target "$config_val") + if [ -n "$config_val" ]; then + config_val=$(get_mntpoint_from_target "$config_val") + DUMP_INSTRUCTION="dump_fs $config_val" + fi + ;; + ext[234] | xfs | btrfs | minix | nfs) + config_val=$(get_mntpoint_from_target "$config_val") + DUMP_INSTRUCTION="dump_fs $config_val" + ;; + raw) + DUMP_INSTRUCTION="dump_raw $config_val" + ;; + ssh) + DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val" + ;; + esac + done < "$KDUMP_CONF_PARSED" } fence_kdump_notify() { - if [ -n "$FENCE_KDUMP_NODES" ]; then - # shellcheck disable=SC2086 - $FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES & - fi + if [ -n "$FENCE_KDUMP_NODES" ]; then + # shellcheck disable=SC2086 + $FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES & + fi } if [ "$1" = "--error-handler" ]; then - get_kdump_confs - do_failure_action - do_final_action + get_kdump_confs + do_failure_action + do_final_action - exit $? + exit $? fi # continue here only if we have to save dump. if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ] && [ ! -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then - exit 0 + exit 0 fi read_kdump_confs fence_kdump_notify if ! get_host_ip; then - derror "get_host_ip exited with non-zero status!" - exit 1 + derror "get_host_ip exited with non-zero status!" + exit 1 fi if [ -z "$DUMP_INSTRUCTION" ]; then - DUMP_INSTRUCTION="dump_fs $NEWROOT" + DUMP_INSTRUCTION="dump_fs $NEWROOT" fi if ! do_kdump_pre; then - derror "kdump_pre script exited with non-zero status!" - do_final_action - # During systemd service to reboot the machine, stop this shell script running - exit 1 + derror "kdump_pre script exited with non-zero status!" + do_final_action + # During systemd service to reboot the machine, stop this shell script running + exit 1 fi make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab' do_dump DUMP_RETVAL=$? if ! do_kdump_post $DUMP_RETVAL; then - derror "kdump_post script exited with non-zero status!" + derror "kdump_post script exited with non-zero status!" fi if [ $DUMP_RETVAL -ne 0 ]; then - exit 1 + exit 1 fi do_final_action From 5debf397fef03931c0736d473a55ebcf6dc08380 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 14 Sep 2021 03:04:08 +0800 Subject: [PATCH 137/454] kdump-lib-initramfs.sh: make it POSIX compatible POSIX doesn't support keyword local, so add double underscore and prefix to variable names, and reduce variable usage, to avoid any variable name conflict. Also reformat the code with `shfmt -s -w kdump-lib-initramfs.sh`. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-lib-initramfs.sh | 92 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index b30b024..0cdb465 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -9,124 +9,122 @@ KDUMP_CONFIG_FILE="/etc/kdump.conf" # Read kdump config in well formated style kdump_read_conf() { - # Following steps are applied in order: strip trailing comment, strip trailing space, - # strip heading space, match non-empty line, remove duplicated spaces between conf name and value - [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE + # Following steps are applied in order: strip trailing comment, strip trailing space, + # strip heading space, match non-empty line, remove duplicated spaces between conf name and value + [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE } # Retrieves config value defined in kdump.conf # $1: config name, sed regexp compatible -kdump_get_conf_val() { - # For lines matching "^\s*$1\s+", remove matched part (config name including space), - # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. - [ -f "$KDUMP_CONFIG_FILE" ] && \ - sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE +kdump_get_conf_val() +{ + # For lines matching "^\s*$1\s+", remove matched part (config name including space), + # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. + [ -f "$KDUMP_CONFIG_FILE" ] && + sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE } is_mounted() { - findmnt -k -n $1 &>/dev/null + findmnt -k -n "$1" > /dev/null 2>&1 } +# $1: info type +# $2: mount source type +# $3: mount source +# $4: extra args get_mount_info() { - local _info_type=$1 _src_type=$2 _src=$3; shift 3 - local _info=$(findmnt -k -n -r -o $_info_type --$_src_type $_src $@) + __kdump_mnt=$(findmnt -k -n -r -o "$1" "--$2" "$3" $4) - [ -z "$_info" ] && [ -e "/etc/fstab" ] && _info=$(findmnt -s -n -r -o $_info_type --$_src_type $_src $@) + [ -z "$__kdump_mnt" ] && [ -e "/etc/fstab" ] && __kdump_mnt=$(findmnt -s -n -r -o "$1" "--$2" "$3" $4) - echo $_info + echo "$__kdump_mnt" } is_ipv6_address() { - echo $1 | grep -q ":" + echo "$1" | grep -q ":" } is_fs_type_nfs() { - [ "$1" = "nfs" ] || [ "$1" = "nfs4" ] + [ "$1" = "nfs" ] || [ "$1" = "nfs4" ] } # If $1 contains dracut_args "--mount", return get_dracut_args_fstype() { - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3 + echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3 } # If $1 contains dracut_args "--mount", return get_dracut_args_target() { - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1 + echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1 } get_save_path() { - local _save_path=$(kdump_get_conf_val path) - [ -z "$_save_path" ] && _save_path=$DEFAULT_PATH + __kdump_path=$(kdump_get_conf_val path) + [ -z "$__kdump_path" ] && __kdump_path=$DEFAULT_PATH - # strip the duplicated "/" - echo $_save_path | tr -s / + # strip the duplicated "/" + echo "$__kdump_path" | tr -s / } get_root_fs_device() { - findmnt -k -f -n -o SOURCE / + findmnt -k -f -n -o SOURCE / } # Return the current underlying device of a path, ignore bind mounts get_target_from_path() { - local _target - - _target=$(df $1 2>/dev/null | tail -1 | awk '{print $1}') - [[ "$_target" == "/dev/root" ]] && [[ ! -e /dev/root ]] && _target=$(get_root_fs_device) - echo $_target + __kdump_target=$(df "$1" 2> /dev/null | tail -1 | awk '{print $1}') + [ "$__kdump_target" = "/dev/root" ] && [ ! -e /dev/root ] && __kdump_target=$(get_root_fs_device) + echo "$__kdump_target" } get_fs_type_from_target() { - get_mount_info FSTYPE source $1 -f + get_mount_info FSTYPE source "$1" -f } get_mntpoint_from_target() { - # --source is applied to ensure non-bind mount is returned - get_mount_info TARGET source $1 -f + # --source is applied to ensure non-bind mount is returned + get_mount_info TARGET source "$1" -f } is_ssh_dump_target() { - [[ $(kdump_get_conf_val ssh) == *@* ]] + kdump_get_conf_val ssh | grep -q @ } is_raw_dump_target() { - [[ $(kdump_get_conf_val raw) ]] + [ -n "$(kdump_get_conf_val raw)" ] } is_nfs_dump_target() { - if [[ $(kdump_get_conf_val nfs) ]]; then - return 0; - fi + if [ -n "$(kdump_get_conf_val nfs)" ]; then + return 0 + fi - if is_fs_type_nfs $(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)"); then - return 0 - fi + if is_fs_type_nfs "$(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)")"; then + return 0 + fi - local _save_path=$(get_save_path) - local _target=$(get_target_from_path $_save_path) - local _fstype=$(get_fs_type_from_target $_target) + if is_fs_type_nfs "$(get_fs_type_from_target "$(get_target_from_path "$(get_save_path)")")"; then + return 0 + fi - if is_fs_type_nfs $_fstype; then - return 0 - fi - - return 1 + return 1 } is_fs_dump_target() { - [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix") ]] + [ -n "$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix")" ] } From 30090f3a15d266937bba6ef2429876e26b5e92d7 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 13 Sep 2021 01:17:05 +0800 Subject: [PATCH 138/454] kdump-lib.sh: replace '[ ]' with '[[ ]]' and get rid of legacy `` Updated file syntax with following command: sed -i -e 's/\(\s\)\[\s\([^]]*\)\s\]/\1\[\[\ \2 \]\]/g' kdump-lib.sh (replace '[ ]' with '[[ ]]') sed -i -e 's/`\([^`]*\)`/\$(\1)/g' kdump-lib.sh (replace `...` with $(...)) And manually updated [[ ... -a ... ]] and [[ ... -o ... ]] with && and ||. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-lib.sh | 148 +++++++++++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index d7cb40e..0dbf485 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -13,16 +13,16 @@ is_fadump_capable() { # Check if firmware-assisted dump is enabled # if no, fallback to kdump check - if [ -f $FADUMP_ENABLED_SYS_NODE ]; then - rc=`cat $FADUMP_ENABLED_SYS_NODE` - [ $rc -eq 1 ] && return 0 + if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then + rc=$(cat $FADUMP_ENABLED_SYS_NODE) + [[ $rc -eq 1 ]] && return 0 fi return 1 } is_squash_available() { for kmodule in squashfs overlay loop; do - if [ -z "$KDUMP_KERNELVER" ]; then + if [[ -z "$KDUMP_KERNELVER" ]]; then modprobe --dry-run $kmodule &>/dev/null || return 1 else modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1 @@ -40,7 +40,7 @@ is_pcs_fence_kdump() { # no pcs or fence_kdump_send executables installed? type -P pcs > /dev/null || return 1 - [ -x $FENCE_KDUMP_SEND ] || return 1 + [[ -x $FENCE_KDUMP_SEND ]] || return 1 # fence kdump not configured? (pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1 @@ -49,7 +49,7 @@ is_pcs_fence_kdump() # Check if fence_kdump is configured using kdump options is_generic_fence_kdump() { - [ -x $FENCE_KDUMP_SEND ] || return 1 + [[ -x $FENCE_KDUMP_SEND ]] || return 1 [[ $(kdump_get_conf_val fence_kdump_nodes) ]] } @@ -59,10 +59,10 @@ to_dev_name() { case "$dev" in UUID=*) - dev=`blkid -U "${dev#UUID=}"` + dev=$(blkid -U "${dev#UUID=}") ;; LABEL=*) - dev=`blkid -L "${dev#LABEL=}"` + dev=$(blkid -L "${dev#LABEL=}") ;; esac echo $dev @@ -78,10 +78,10 @@ get_user_configured_dump_disk() local _target _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw") - [ -n "$_target" ] && echo $_target && return + [[ -n "$_target" ]] && echo $_target && return _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") - [ -b "$_target" ] && echo $_target + [[ -b "$_target" ]] && echo $_target } get_block_dump_target() @@ -93,12 +93,12 @@ get_block_dump_target() fi _target=$(get_user_configured_dump_disk) - [ -n "$_target" ] && echo $(to_dev_name $_target) && return + [[ -n "$_target" ]] && echo $(to_dev_name $_target) && return # Get block device name from local save path _path=$(get_save_path) _target=$(get_target_from_path $_path) - [ -b "$_target" ] && echo $(to_dev_name $_target) + [[ -b "$_target" ]] && echo $(to_dev_name $_target) } is_dump_to_rootfs() @@ -113,7 +113,7 @@ get_failure_action_target() if is_dump_to_rootfs; then # Get rootfs device name _target=$(get_root_fs_device) - [ -b "$_target" ] && echo $(to_dev_name $_target) && return + [[ -b "$_target" ]] && echo $(to_dev_name $_target) && return # Then, must be nfs root echo "nfs" fi @@ -126,7 +126,7 @@ get_kdump_targets() local kdump_targets _target=$(get_block_dump_target) - if [ -n "$_target" ]; then + if [[ -n "$_target" ]]; then kdump_targets=$_target elif is_ssh_dump_target; then kdump_targets="ssh" @@ -136,7 +136,7 @@ get_kdump_targets() # Add the root device if dump_to_rootfs is specified. _root=$(get_failure_action_target) - if [ -n "$_root" -a "$kdump_targets" != "$_root" ]; then + if [[ -n "$_root" ]] && [[ "$kdump_targets" != "$_root" ]]; then kdump_targets="$kdump_targets $_root" fi @@ -204,10 +204,10 @@ get_kdump_mntpoint_from_target() # mount under /kdumproot if dump target is not mounted in first kernel # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel. # systemd will be in charge to umount it. - if [ -z "$_mntpoint" ];then + if [[ -z "$_mntpoint" ]];then _mntpoint="/kdumproot" else - if [ "$_mntpoint" = "/" ];then + if [[ "$_mntpoint" = "/" ]];then _mntpoint="/sysroot" else _mntpoint="/kdumproot/$_mntpoint" @@ -223,10 +223,10 @@ kdump_get_persistent_dev() { case "$dev" in UUID=*) - dev=`blkid -U "${dev#UUID=}"` + dev=$(blkid -U "${dev#UUID=}") ;; LABEL=*) - dev=`blkid -L "${dev#LABEL=}"` + dev=$(blkid -L "${dev#LABEL=}") ;; esac echo $(get_persistent_dev "$dev") @@ -253,9 +253,9 @@ get_remote_host() is_hostname() { - local _hostname=`echo $1 | grep ":"` + local _hostname=$(echo $1 | grep ":") - if [ -n "$_hostname" ]; then + if [[ -n "$_hostname" ]]; then return 1 fi echo $1 | grep -q "[a-zA-Z]" @@ -264,9 +264,9 @@ is_hostname() # Copied from "/etc/sysconfig/network-scripts/network-functions" get_hwaddr() { - if [ -f "/sys/class/net/${1}/address" ]; then + if [[ -f "/sys/class/net/${1}/address" ]]; then awk '{ print toupper($0) }' < /sys/class/net/${1}/address - elif [ -d "/sys/class/net/${1}" ]; then + elif [[ -d "/sys/class/net/${1}" ]]; then LC_ALL= LANG= ip -o link show ${1} 2>/dev/null | \ awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/, "\\1", 1)); }' @@ -347,7 +347,7 @@ get_ifcfg_by_name() is_nm_running() { - [ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ] + [[ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ]] } is_nm_handling() @@ -371,7 +371,7 @@ get_ifcfg_nmcli() nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2>/dev/null \ | grep "${1}" | head -1 | cut -d':' -f1) ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}") - [ -z "${ifcfg_file}" ] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}") + [[ -z "${ifcfg_file}" ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}") fi echo -n "${ifcfg_file}" @@ -383,15 +383,15 @@ get_ifcfg_legacy() local ifcfg_file ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}" - [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return + [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return ifcfg_file=$(get_ifcfg_by_name "${1}") - [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return + [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return local hwaddr=$(get_hwaddr "${1}") - if [ -n "$hwaddr" ]; then + if [[ -n "$hwaddr" ]]; then ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}") - [ -f "${ifcfg_file}" ] && echo -n "${ifcfg_file}" && return + [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return fi ifcfg_file=$(get_ifcfg_by_device "${1}") @@ -405,7 +405,7 @@ get_ifcfg_filename() { local ifcfg_file ifcfg_file=$(get_ifcfg_nmcli "${1}") - if [ -z "${ifcfg_file}" ]; then + if [[ -z "${ifcfg_file}" ]]; then ifcfg_file=$(get_ifcfg_legacy "${1}") fi @@ -432,11 +432,11 @@ is_dracut_mod_omitted() { is_wdt_active() { local active - [ -d /sys/class/watchdog ] || return 1 + [[ -d /sys/class/watchdog ]] || return 1 for dir in /sys/class/watchdog/*; do - [ -f "$dir/state" ] || continue + [[ -f "$dir/state" ]] || continue active=$(< "$dir/state") - [ "$active" = "active" ] && return 0 + [[ "$active" = "active" ]] && return 0 done return 1 } @@ -454,7 +454,7 @@ check_crash_mem_reserved() local mem_reserved mem_reserved=$(cat /sys/kernel/kexec_crash_size) - if [ $mem_reserved -eq 0 ]; then + if [[ $mem_reserved -eq 0 ]]; then derror "No memory reserved for crash kernel" return 1 fi @@ -464,7 +464,7 @@ check_crash_mem_reserved() check_kdump_feasibility() { - if [ ! -e /sys/kernel/kexec_crash_loaded ]; then + if [[ ! -e /sys/kernel/kexec_crash_loaded ]]; then derror "Kdump is not supported on this kernel" return 1 fi @@ -474,13 +474,13 @@ check_kdump_feasibility() check_current_kdump_status() { - if [ ! -f /sys/kernel/kexec_crash_loaded ];then + if [[ ! -f /sys/kernel/kexec_crash_loaded ]];then derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel" return 1 fi - rc=`cat /sys/kernel/kexec_crash_loaded` - if [ $rc == 1 ]; then + rc=$(cat /sys/kernel/kexec_crash_loaded) + if [[ $rc == 1 ]]; then return 0 else return 1 @@ -496,11 +496,11 @@ remove_cmdline_param() shift for arg in $@; do - cmdline=`echo $cmdline | \ + cmdline=$(echo "$cmdline" | \ sed -e "s/\b$arg=[^ ]*//g" \ -e "s/^$arg\b//g" \ -e "s/[[:space:]]$arg\b//g" \ - -e "s/\s\+/ /g"` + -e "s/\s\+/ /g") done echo $cmdline } @@ -529,7 +529,7 @@ append_cmdline() local newstr=${cmdline/$2/""} # unchanged str implies argument wasn't there - if [ "$cmdline" == "$newstr" ]; then + if [[ "$cmdline" == "$newstr" ]]; then cmdline="${cmdline} ${2}=${3}" fi @@ -540,8 +540,8 @@ append_cmdline() # 4GB of ram available. Returns 1 if we do, 0 if we dont need_64bit_headers() { - return `tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); \ - print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }'` + return "$(tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); + print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }')" } # Check if secure boot is being enforced. @@ -561,11 +561,11 @@ is_secure_boot_enforced() # On powerpc, secure boot is enforced if: # host secure boot: /ibm,secure-boot/os-secureboot-enforcing DT property exists # guest secure boot: /ibm,secure-boot >= 2 - if [ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]; then + if [[ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]]; then return 0 fi - if [ -f /proc/device-tree/ibm,secure-boot ] && \ - [ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]; then + if [[ -f /proc/device-tree/ibm,secure-boot ]] && \ + [[ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]]; then return 0 fi @@ -573,11 +573,11 @@ is_secure_boot_enforced() secure_boot_file=$(find /sys/firmware/efi/efivars -name SecureBoot-* 2>/dev/null) setup_mode_file=$(find /sys/firmware/efi/efivars -name SetupMode-* 2>/dev/null) - if [ -f "$secure_boot_file" ] && [ -f "$setup_mode_file" ]; then + if [[ -f "$secure_boot_file" ]] && [[ -f "$setup_mode_file" ]]; then secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' $secure_boot_file|cut -d' ' -f 5) setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' $setup_mode_file|cut -d' ' -f 5) - if [ "$secure_boot_byte" = "1" ] && [ "$setup_mode_byte" = "0" ]; then + if [[ "$secure_boot_byte" = "1" ]] && [[ "$setup_mode_byte" = "0" ]]; then return 0 fi fi @@ -599,22 +599,22 @@ prepare_kexec_args() local kexec_args=$1 local found_elf_args - ARCH=`uname -m` - if [ "$ARCH" == "i686" -o "$ARCH" == "i386" ] + ARCH=$(uname -m) + if [[ "$ARCH" == "i686" ]] || [[ "$ARCH" == "i386" ]] then need_64bit_headers - if [ $? == 1 ] + if [[ $? == 1 ]] then - found_elf_args=`echo $kexec_args | grep elf32-core-headers` - if [ -n "$found_elf_args" ] + found_elf_args=$(echo $kexec_args | grep elf32-core-headers) + if [[ -n "$found_elf_args" ]] then dwarn "Warning: elf32-core-headers overrides correct elf64 setting" else kexec_args="$kexec_args --elf64-core-headers" fi else - found_elf_args=`echo $kexec_args | grep elf64-core-headers` - if [ -z "$found_elf_args" ] + found_elf_args=$(echo $kexec_args | grep elf64-core-headers) + if [[ -z "$found_elf_args" ]] then kexec_args="$kexec_args --elf32-core-headers" fi @@ -635,7 +635,7 @@ prepare_kdump_bootinfo() local boot_imglist boot_dirlist boot_initrdlist curr_kver="$(uname -r)" local machine_id - if [ -z "$KDUMP_KERNELVER" ]; then + if [[ -z "$KDUMP_KERNELVER" ]]; then KDUMP_KERNELVER="$(uname -r)" fi @@ -645,20 +645,20 @@ prepare_kdump_bootinfo() # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format local boot_img="$(cat /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/")" - if [ -n "$boot_img" ]; then + if [[ -n "$boot_img" ]]; then boot_imglist="$boot_img $boot_imglist" fi for dir in $boot_dirlist; do for img in $boot_imglist; do - if [ -f "$dir/$img" ]; then + if [[ -f "$dir/$img" ]]; then KDUMP_KERNEL=$(echo $dir/$img | tr -s '/') break 2 fi done done - if ! [ -e "$KDUMP_KERNEL" ]; then + if ! [[ -e "$KDUMP_KERNEL" ]]; then derror "Failed to detect kdump kernel location" return 1 fi @@ -669,7 +669,7 @@ prepare_kdump_bootinfo() # Default initrd should just stay aside of kernel image, try to find it in KDUMP_BOOTDIR boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" for initrd in $boot_initrdlist; do - if [ -f "$KDUMP_BOOTDIR/$initrd" ]; then + if [[ -f "$KDUMP_BOOTDIR/$initrd" ]]; then defaut_initrd_base="$initrd" DEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base" break @@ -687,7 +687,7 @@ prepare_kdump_bootinfo() kdump_initrd_base=${defaut_initrd_base}kdump fi - # Place kdump initrd in `/var/lib/kdump` if `KDUMP_BOOTDIR` not writable + # Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable if [[ ! -w "$KDUMP_BOOTDIR" ]];then var_target_initrd_dir="/var/lib/kdump" mkdir -p "$var_target_initrd_dir" @@ -724,7 +724,7 @@ prepare_cmdline() { local cmdline id - if [ -z "$1" ]; then + if [[ -z "$1" ]]; then cmdline=$(cat /proc/cmdline) else cmdline="$1" @@ -754,7 +754,7 @@ prepare_cmdline() cmdline="${cmdline} $3" id=$(get_bootcpu_apicid) - if [ ! -z ${id} ] ; then + if [[ ! -z ${id} ]] ; then cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id}) fi @@ -803,7 +803,7 @@ get_recommend_size() last_unit="" start=${_ck_cmdline: :1} - if [ $mem_size -lt $start ]; then + if [[ $mem_size -lt $start ]]; then echo "0M" return fi @@ -813,10 +813,10 @@ get_recommend_size() recommend=$(echo $i | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $2 }') size=${end: : -1} unit=${end: -1} - if [ $unit == 'T' ]; then + if [[ $unit == 'T' ]]; then let size=$size*1024 fi - if [ $mem_size -lt $size ]; then + if [[ $mem_size -lt $size ]]; then echo $recommend IFS="$OLDIFS" return @@ -826,28 +826,28 @@ get_recommend_size() } # return recommended size based on current system RAM size -# $1: kernel version, if not set, will defaults to `uname -r` +# $1: kernel version, if not set, will defaults to $(uname -r) kdump_get_arch_recommend_size() { local kernel=$1 arch - if ! [ -r "/proc/iomem" ] ; then + if ! [[ -r "/proc/iomem" ]] ; then echo "Error, can not access /proc/iomem." return 1 fi - [ -z "$kernel" ] && kernel=$(uname -r) + [[ -z "$kernel" ]] && kernel=$(uname -r) ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2>/dev/null) - if [ -n "$ck_cmdline" ]; then + if [[ -n "$ck_cmdline" ]]; then ck_cmdline=${ck_cmdline#crashkernel=} else arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]') - if [ "$arch" = "X86_64" ] || [ "$arch" = "S390X" ]; then + if [[ "$arch" = "X86_64" ]] || [[ "$arch" = "S390X" ]]; then ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" - elif [ "$arch" = "AARCH64" ]; then + elif [[ "$arch" = "AARCH64" ]]; then ck_cmdline="2G-:448M" - elif [ "$arch" = "PPC64LE" ]; then + elif [[ "$arch" = "PPC64LE" ]]; then if is_fadump_capable; then ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" else @@ -923,7 +923,7 @@ try_decompress() # "grep" that report the byte offset of the line instead of the pattern. # Try to find the header ($1) and decompress from here - for pos in `tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"` + for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2") do if ! type -P $3 > /dev/null; then ddebug "Signiature detected but '$3' is missing, skip this decompressor" From 58d3e6db3a2f066ea8e48fe9a8c77a6bb8ca7159 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 15:20:42 +0800 Subject: [PATCH 139/454] kdump-lib.sh: rework nmcli related functions This fixes word splitting issue with nmcli args. Current kexec-tools scripts won't call nmcli with correct arguments when there are space in network interface name. nmcli expects multiple parameters, but get_nmcli_value_by_field only accepts two params and depends on shell word splitting to split the _nm_show_cmd into multiple params, which is very fragile. So switch the param order, simplified this function and now multiple params can be used properly. And get_nmcli_connection_show_cmd_by_ifname returns multiple nmcli params in a single variable, it depend on shell word splitting to split the words when calling nmcli. But this is very fragile and break easily when there are any special character in the connection path. This function is only introduced to get and cache the nmcli command which contains the "connection name". Actually only cache the "connection path" is enough. Callers should just call get_nmcli_connection_apath_by_ifname to cache the path, and a new helper get_nmcli_field_by_conpath is introduced here to get value from nmcli. This way "connection path" can contain any character. Also get rid of another nmcli_cmd usage in get_nmcli_connection_apath_by_ifname which stores multiple params in a single bash variable separated by space. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-module-setup.sh | 37 ++++++++++++++++++------------------- kdump-lib.sh | 32 ++++++++++---------------------- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 80b5582..a5e4b67 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -84,14 +84,13 @@ source_ifcfg_file() { fi } -# $1: nmcli connection show output kdump_setup_dns() { local _netdev="$1" - local _nm_show_cmd="$2" + local _conpath="$2" local _nameserver _dns _tmp array local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf - _tmp=$(get_nmcli_value_by_field "$_nm_show_cmd" "IP4.DNS") + _tmp=$(get_nmcli_field_by_conpath "IP4.DNS" "$_conpath") # shellcheck disable=SC2206 array=(${_tmp//|/ }) if [[ ${array[*]} ]]; then @@ -355,7 +354,7 @@ kdump_setup_bridge() { _dev=${_dev##*/} _kdumpdev=$_dev if kdump_is_bond "$_dev"; then - (kdump_setup_bond "$_dev" "$(get_nmcli_connection_show_cmd_by_ifname "$_dev")") || exit 1 + (kdump_setup_bond "$_dev" "$(get_nmcli_connection_apath_by_ifname "$_dev")") || exit 1 elif kdump_is_team "$_dev"; then kdump_setup_team "$_dev" elif kdump_is_vlan "$_dev"; then @@ -375,7 +374,7 @@ kdump_setup_bridge() { # bond=bond0:eth0,eth1:mode=balance-rr kdump_setup_bond() { local _netdev="$1" - local _nm_show_cmd="$2" + local _conpath="$2" local _dev _mac _slaves _kdumpdev _bondoptions for _dev in $(cat "/sys/class/net/$_netdev/bonding/slaves"); do _mac=$(kdump_get_perm_addr "$_dev") @@ -385,7 +384,7 @@ kdump_setup_bond() { done echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf" - _bondoptions=$(get_nmcli_value_by_field "$_nm_show_cmd" "bond.options") + _bondoptions=$(get_nmcli_field_by_conpath "bond.options" "$_conpath") if [[ -z $_bondoptions ]]; then dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." @@ -436,7 +435,7 @@ kdump_setup_vlan() { derror "Vlan over bridge is not supported!" exit 1 elif kdump_is_bond "$_phydev"; then - (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_show_cmd_by_ifname "$_phydev")") || exit 1 + (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_apath_by_ifname "$_phydev")") || exit 1 echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" else _kdumpdev="$(kdump_setup_ifname "$_phydev")" @@ -474,18 +473,18 @@ find_online_znet_device() { # setup s390 znet cmdline # $1: netdev (ifname) -# $2: nmcli connection show output +# $2: nmcli connection path kdump_setup_znet() { local _netdev="$1" - local _nmcli_cmd="$2" + local _conpath="$2" local s390_prefix="802-3-ethernet.s390-" local _options="" local NETTYPE local SUBCHANNELS - NETTYPE=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}nettype") - SUBCHANNELS=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}subchannels") - _options=$(get_nmcli_value_by_field "$_nmcli_cmd" "${s390_prefix}options") + NETTYPE=$(get_nmcli_field_by_conpath "${s390_prefix}nettype" "$_conpath") + SUBCHANNELS=$(get_nmcli_field_by_conpath "${s390_prefix}subchannels" "$_conpath") + _options=$(get_nmcli_field_by_conpath "${s390_prefix}options" "$_conpath") if [[ -z $NETTYPE || -z $SUBCHANNELS || -z $_options ]]; then dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script." @@ -532,22 +531,22 @@ kdump_get_remote_ip() { # initramfs accessing giving destination # $1: destination host kdump_install_net() { - local _destaddr _srcaddr _route _netdev _nm_show_cmd kdumpnic + local _destaddr _srcaddr _route _netdev _conpath kdumpnic local _static _proto _ip_conf _ip_opts _ifname_opts - local _znet_netdev _nm_show_cmd_znet + local _znet_netdev _znet_conpath _destaddr=$(kdump_get_remote_ip "$1") _route=$(kdump_get_ip_route "$_destaddr") _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") - _nm_show_cmd=$(get_nmcli_connection_show_cmd_by_ifname "$_netdev") + _conpath=$(get_nmcli_connection_apath_by_ifname "$_netdev") _netmac=$(kdump_get_mac_addr "$_netdev") kdumpnic=$(kdump_setup_ifname "$_netdev") _znet_netdev=$(find_online_znet_device) if [[ -n $_znet_netdev ]]; then - _nm_show_cmd_znet=$(get_nmcli_connection_show_cmd_by_ifname "$_znet_netdev") - if ! (kdump_setup_znet "$_znet_netdev" "$_nm_show_cmd_znet"); then + _znet_conpath=$(get_nmcli_connection_apath_by_ifname "$_znet_netdev") + if ! (kdump_setup_znet "$_znet_netdev" "$_znet_conpath"); then derror "Failed to set up znet" exit 1 fi @@ -577,7 +576,7 @@ kdump_install_net() { if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then - (kdump_setup_bond "$_netdev" "$_nm_show_cmd") || exit 1 + (kdump_setup_bond "$_netdev" "$_conpath") || exit 1 elif kdump_is_team "$_netdev"; then kdump_setup_team "$_netdev" elif kdump_is_vlan "$_netdev"; then @@ -587,7 +586,7 @@ kdump_install_net() { echo "$_ifname_opts" >> "$_ip_conf" fi - kdump_setup_dns "$_netdev" "$_nm_show_cmd" + kdump_setup_dns "$_netdev" "$_conpath" if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then # network-manager module needs this parameter diff --git a/kdump-lib.sh b/kdump-lib.sh index 0dbf485..24a02b5 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -275,6 +275,7 @@ get_hwaddr() # Get value by a field using "nmcli -g" +# Usage: get_nmcli_value_by_field # # "nmcli --get-values" allows us to retrive value(s) by field, for example, # nmcli --get-values connection show /org/freedesktop/NetworkManager/ActiveConnection/1 @@ -285,12 +286,16 @@ get_hwaddr() # bond.options "mode=balance-rr" get_nmcli_value_by_field() { - local _nm_show_cmd=$1 - local _field=$2 + LANG=C nmcli --get-values "$@" +} - local val=$(LANG=C nmcli --get-values $_field $_nm_show_cmd) +# Get nmcli field value of an connection apath (a D-Bus active connection path) +# Usage: get_nmcli_field_by_apath +get_nmcli_field_by_conpath() +{ + local _field=$1 _apath=$2 - echo -n "$val" + get_nmcli_value_by_field "$_field" connection show "$_apath" } # Get nmcli connection apath (a D-Bus active connection path ) by ifname @@ -300,25 +305,8 @@ get_nmcli_value_by_field() get_nmcli_connection_apath_by_ifname() { local _ifname=$1 - local _nm_show_cmd="device show $_ifname" - local _apath=$(get_nmcli_value_by_field "$_nm_show_cmd" "GENERAL.CON-PATH") - - echo -n "$_apath" -} - -# Get nmcli connection show cmd by ifname -# -# "$_apath" is supposed to not contain any chracter that -# need to be escapded, e.g. space. Otherwise get_nmcli_value_by_field -# would fail. -get_nmcli_connection_show_cmd_by_ifname() -{ - local _ifname="$1" - local _apath=$(get_nmcli_connection_apath_by_ifname "$_ifname") - local _nm_show_cmd="connection show $_apath" - - echo -n "$_nm_show_cmd" + get_nmcli_value_by_field "GENERAL.CON-PATH" device show "$_ifname" } get_ifcfg_by_device() From 53813e8b9af280315962ac6656318f94b1daf563 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 02:48:17 +0800 Subject: [PATCH 140/454] kdump-lib.sh: remove useless echo and cat Replace echo "$(cmd)" and "var=$(cmd); echo $var" with just `cmd`. And remove some useless cat. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-lib.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 24a02b5..8624e19 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -14,7 +14,7 @@ is_fadump_capable() # Check if firmware-assisted dump is enabled # if no, fallback to kdump check if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then - rc=$(cat $FADUMP_ENABLED_SYS_NODE) + rc=$(<$FADUMP_ENABLED_SYS_NODE) [[ $rc -eq 1 ]] && return 0 fi return 1 @@ -59,13 +59,14 @@ to_dev_name() { case "$dev" in UUID=*) - dev=$(blkid -U "${dev#UUID=}") + blkid -U "${dev#UUID=}" ;; LABEL=*) - dev=$(blkid -L "${dev#LABEL=}") + blkid -L "${dev#LABEL=}" ;; + *) + echo "$dev" esac - echo $dev } is_user_configured_dump_target() @@ -93,12 +94,12 @@ get_block_dump_target() fi _target=$(get_user_configured_dump_disk) - [[ -n "$_target" ]] && echo $(to_dev_name $_target) && return + [[ -n "$_target" ]] && to_dev_name $_target && return # Get block device name from local save path _path=$(get_save_path) _target=$(get_target_from_path $_path) - [[ -b "$_target" ]] && echo $(to_dev_name $_target) + [[ -b "$_target" ]] && to_dev_name $_target } is_dump_to_rootfs() @@ -113,7 +114,7 @@ get_failure_action_target() if is_dump_to_rootfs; then # Get rootfs device name _target=$(get_root_fs_device) - [[ -b "$_target" ]] && echo $(to_dev_name $_target) && return + [[ -b "$_target" ]] && to_dev_name $_target && return # Then, must be nfs root echo "nfs" fi @@ -441,7 +442,7 @@ check_crash_mem_reserved() { local mem_reserved - mem_reserved=$(cat /sys/kernel/kexec_crash_size) + mem_reserved=$( Date: Wed, 8 Sep 2021 13:31:31 +0800 Subject: [PATCH 141/454] kdump-lib.sh: fix arithmetic operation syntax Get rid of let, and remove useless '$' on arithmetic variables. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-lib.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 8624e19..aff395b 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -777,7 +777,7 @@ get_system_size() # replace '-' with '+0x' and '+' with '-0x' sum=$( echo $result | sed -e 's/-/K0x/g' | sed -e 's/+/-0x/g' | sed -e 's/K/+/g' ) size=$(printf "%d\n" $(($sum))) - let size=$size/1024/1024/1024 + size=$((size / 1024 / 1024 / 1024)) echo $size } @@ -803,7 +803,7 @@ get_recommend_size() size=${end: : -1} unit=${end: -1} if [[ $unit == 'T' ]]; then - let size=$size*1024 + size=$((size * 1024)) fi if [[ $mem_size -lt $size ]]; then echo $recommend @@ -899,7 +899,7 @@ get_vmlinux_size() local size=0 while read _type _offset _virtaddr _physaddr _fsize _msize _flg _aln; do - size=$(( $size + $_msize )) + size=$(( size + _msize )) done <<< $(readelf -l -W $1 | grep "^ LOAD" 2>/dev/stderr) echo $size @@ -954,7 +954,7 @@ get_kernel_size() # Fallback to use iomem local _size=0 for _seg in $(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1); do - _size=$(( $_size + 0x${_seg#*-} - 0x${_seg%-*} )) + _size=$(( _size + 0x${_seg#*-} - 0x${_seg%-*} )) done echo $_size } From 319219d23b003310f457e3ba549bf0fa0254d7da Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 13 Sep 2021 01:17:23 +0800 Subject: [PATCH 142/454] kdump-lib.sh: fix a few ambiguous or redundant code Fix a few ambiguous syntax issues and remove some unused variables. Also refactor some code to make it more robust. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-lib.sh | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index aff395b..6705f27 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -176,7 +176,7 @@ get_bind_mount_source() echo $_mnt$_path && return fi - local _fsroot=${_src#$_src_nofsroot[} + local _fsroot=${_src#${_src_nofsroot}[} _fsroot=${_fsroot%]} _mnt=$(get_mount_info TARGET source $_src_nofsroot -f) @@ -621,14 +621,14 @@ prepare_kexec_args() # prepare_kdump_bootinfo() { - local boot_imglist boot_dirlist boot_initrdlist curr_kver="$(uname -r)" + local boot_imglist boot_dirlist boot_initrdlist local machine_id if [[ -z "$KDUMP_KERNELVER" ]]; then KDUMP_KERNELVER="$(uname -r)" fi - read machine_id < /etc/machine-id + read -r machine_id < /etc/machine-id boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"} boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG" @@ -743,8 +743,8 @@ prepare_cmdline() cmdline="${cmdline} $3" id=$(get_bootcpu_apicid) - if [[ ! -z ${id} ]] ; then - cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id}) + if [[ -n ${id} ]] ; then + cmdline=$(append_cmdline "$cmdline" disable_cpu_apicid "$id") fi # If any watchdog is used, set it's pretimeout to 0. pretimeout let @@ -775,7 +775,7 @@ get_system_size() result=$(grep "System RAM" /proc/iomem | awk -F ":" '{ print $1 }' | tr [:lower:] [:upper:] | paste -sd+) result="+$result" # replace '-' with '+0x' and '+' with '-0x' - sum=$( echo $result | sed -e 's/-/K0x/g' | sed -e 's/+/-0x/g' | sed -e 's/K/+/g' ) + sum=$(echo "$result" | sed -e 's/-/K0x/g' -e 's/+/-0x/g' -e 's/K/+/g') size=$(printf "%d\n" $(($sum))) size=$((size / 1024 / 1024 / 1024)) @@ -788,9 +788,6 @@ get_recommend_size() local _ck_cmdline=$2 local OLDIFS="$IFS" - last_sz="" - last_unit="" - start=${_ck_cmdline: :1} if [[ $mem_size -lt $start ]]; then echo "0M" @@ -845,7 +842,7 @@ kdump_get_arch_recommend_size() fi fi - ck_cmdline=$(echo $ck_cmdline | sed -e 's/-:/-102400T:/g') + ck_cmdline=${ck_cmdline//-:/-102400T:} sys_mem=$(get_system_size) get_recommend_size "$sys_mem" "$ck_cmdline" @@ -896,11 +893,11 @@ check_vmlinux() get_vmlinux_size() { - local size=0 + local size=0 _msize - while read _type _offset _virtaddr _physaddr _fsize _msize _flg _aln; do + while read -r _msize; do size=$(( size + _msize )) - done <<< $(readelf -l -W $1 | grep "^ LOAD" 2>/dev/stderr) + done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2>/dev/stderr)" echo $size } @@ -952,9 +949,9 @@ get_kernel_size() [[ $? -eq 0 ]] && get_vmlinux_size $tmp && return 0 # Fallback to use iomem - local _size=0 - for _seg in $(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1); do - _size=$(( _size + 0x${_seg#*-} - 0x${_seg%-*} )) - done + local _size=0 _seg + while read -r _seg; do + _size=$(( _size + 0x${_seg#*-} - 0x${_seg%-*} )) + done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)" echo $_size } From 4f01cb1b0a4e1ea9467e9ace34d14dcb2fbe135a Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 13 Sep 2021 01:18:04 +0800 Subject: [PATCH 143/454] kdump-lib.sh: fix variable quoting issue Fixed quoting issues found by shellcheck, no feature change. This should fix many errors when there is space in any shell variables. And fixed how remove_cmdline_param is being called in prepare_cmdline. Kernel parameters can have space like: param="spaces in here". So currently remove_cmdline_param is broken since its args always get split by space. But prepare_cmdline is expecting remove_cmdline_param to split its args by space and passing a list of kernel args separated by space as a whole arg. So fix that by using `xargs` to parse and split the args properly, then call remove_cmdline_param. Following quoting related issues are fixed (check the link for example code and what could go wrong): https://github.com/koalaman/shellcheck/wiki/SC1007 https://github.com/koalaman/shellcheck/wiki/SC2046 https://github.com/koalaman/shellcheck/wiki/SC2053 https://github.com/koalaman/shellcheck/wiki/SC2060 https://github.com/koalaman/shellcheck/wiki/SC2068 https://github.com/koalaman/shellcheck/wiki/SC2086 Signed-off-by: Kairui Song --- kdump-lib.sh | 132 ++++++++++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 6705f27..64c6e4f 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -25,7 +25,7 @@ is_squash_available() { if [[ -z "$KDUMP_KERNELVER" ]]; then modprobe --dry-run $kmodule &>/dev/null || return 1 else - modprobe -S $KDUMP_KERNELVER --dry-run $kmodule &>/dev/null || return 1 + modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &>/dev/null || return 1 fi done } @@ -79,10 +79,10 @@ get_user_configured_dump_disk() local _target _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw") - [[ -n "$_target" ]] && echo $_target && return + [[ -n "$_target" ]] && echo "$_target" && return _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") - [[ -b "$_target" ]] && echo $_target + [[ -b "$_target" ]] && echo "$_target" } get_block_dump_target() @@ -94,12 +94,12 @@ get_block_dump_target() fi _target=$(get_user_configured_dump_disk) - [[ -n "$_target" ]] && to_dev_name $_target && return + [[ -n "$_target" ]] && to_dev_name "$_target" && return # Get block device name from local save path _path=$(get_save_path) - _target=$(get_target_from_path $_path) - [[ -b "$_target" ]] && to_dev_name $_target + _target=$(get_target_from_path "$_path") + [[ -b "$_target" ]] && to_dev_name "$_target" } is_dump_to_rootfs() @@ -114,7 +114,7 @@ get_failure_action_target() if is_dump_to_rootfs; then # Get rootfs device name _target=$(get_root_fs_device) - [[ -b "$_target" ]] && to_dev_name $_target && return + [[ -b "$_target" ]] && to_dev_name "$_target" && return # Then, must be nfs root echo "nfs" fi @@ -158,27 +158,27 @@ get_kdump_targets() # part is the bind mounted directory which quotes by bracket "[]". get_bind_mount_source() { - local _mnt=$(df $1 | tail -1 | awk '{print $NF}') + local _mnt=$(df "$1" | tail -1 | awk '{print $NF}') local _path=${1#$_mnt} - local _src=$(get_mount_info SOURCE target $_mnt -f) - local _opt=$(get_mount_info OPTIONS target $_mnt -f) - local _fstype=$(get_mount_info FSTYPE target $_mnt -f) + local _src=$(get_mount_info SOURCE target "$_mnt" -f) + local _opt=$(get_mount_info OPTIONS target "$_mnt" -f) + local _fstype=$(get_mount_info FSTYPE target "$_mnt" -f) # bind mount in fstab if [[ -d "$_src" ]] && [[ "$_fstype" = none ]] && (echo "$_opt" | grep -q "\bbind\b"); then - echo $_src$_path && return + echo "$_src$_path" && return fi # direct mount - local _src_nofsroot=$(get_mount_info SOURCE target $_mnt -v -f) - if [[ $_src_nofsroot = $_src ]]; then - echo $_mnt$_path && return + local _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f) + if [[ $_src_nofsroot = "$_src" ]]; then + echo "$_mnt$_path" && return fi local _fsroot=${_src#${_src_nofsroot}[} _fsroot=${_fsroot%]} - _mnt=$(get_mount_info TARGET source $_src_nofsroot -f) + _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) # for btrfs, _fsroot will also contain the subvol value as well, strip it if [[ "$_fstype" = btrfs ]]; then @@ -187,19 +187,19 @@ get_bind_mount_source() _subvol=${_subvol%,*} _fsroot=${_fsroot#$_subvol} fi - echo $_mnt$_fsroot$_path + echo "$_mnt$_fsroot$_path" } get_mntopt_from_target() { - get_mount_info OPTIONS source $1 -f + get_mount_info OPTIONS source "$1" -f } # Get the path where the target will be mounted in kdump kernel # $1: kdump target device get_kdump_mntpoint_from_target() { - local _mntpoint=$(get_mntpoint_from_target $1) + local _mntpoint=$(get_mntpoint_from_target "$1") # mount under /sysroot if dump to root disk or mount under # mount under /kdumproot if dump target is not mounted in first kernel @@ -249,26 +249,26 @@ get_remote_host() _config_val=${_config_val%:/*} _config_val=${_config_val#[} _config_val=${_config_val%]} - echo $_config_val + echo "$_config_val" } is_hostname() { - local _hostname=$(echo $1 | grep ":") + local _hostname=$(echo "$1" | grep ":") if [[ -n "$_hostname" ]]; then return 1 fi - echo $1 | grep -q "[a-zA-Z]" + echo "$1" | grep -q "[a-zA-Z]" } # Copied from "/etc/sysconfig/network-scripts/network-functions" get_hwaddr() { - if [[ -f "/sys/class/net/${1}/address" ]]; then - awk '{ print toupper($0) }' < /sys/class/net/${1}/address - elif [[ -d "/sys/class/net/${1}" ]]; then - LC_ALL= LANG= ip -o link show ${1} 2>/dev/null | \ + if [[ -f "/sys/class/net/$1/address" ]]; then + awk '{ print toupper($0) }' < "/sys/class/net/$1/address" + elif [[ -d "/sys/class/net/$1" ]]; then + LC_ALL="" LANG="" ip -o link show "$1" 2>/dev/null | \ awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/, "\\1", 1)); }' fi @@ -484,14 +484,14 @@ remove_cmdline_param() local cmdline=$1 shift - for arg in $@; do + for arg in "$@"; do cmdline=$(echo "$cmdline" | \ sed -e "s/\b$arg=[^ ]*//g" \ -e "s/^$arg\b//g" \ -e "s/[[:space:]]$arg\b//g" \ -e "s/\s\+/ /g") done - echo $cmdline + echo "$cmdline" } # @@ -522,7 +522,7 @@ append_cmdline() cmdline="${cmdline} ${2}=${3}" fi - echo $cmdline + echo "$cmdline" } # This function check iomem and determines if we have more than @@ -559,12 +559,12 @@ is_secure_boot_enforced() fi # Detect secure boot on x86 and arm64 - secure_boot_file=$(find /sys/firmware/efi/efivars -name SecureBoot-* 2>/dev/null) - setup_mode_file=$(find /sys/firmware/efi/efivars -name SetupMode-* 2>/dev/null) + secure_boot_file=$(find /sys/firmware/efi/efivars -name "SecureBoot-*" 2>/dev/null) + setup_mode_file=$(find /sys/firmware/efi/efivars -name "SetupMode-*" 2>/dev/null) if [[ -f "$secure_boot_file" ]] && [[ -f "$setup_mode_file" ]]; then - secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' $secure_boot_file|cut -d' ' -f 5) - setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' $setup_mode_file|cut -d' ' -f 5) + secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' "$secure_boot_file" | cut -d' ' -f 5) + setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' "$setup_mode_file" | cut -d' ' -f 5) if [[ "$secure_boot_byte" = "1" ]] && [[ "$setup_mode_byte" = "0" ]]; then return 0 @@ -594,7 +594,7 @@ prepare_kexec_args() need_64bit_headers if [[ $? == 1 ]] then - found_elf_args=$(echo $kexec_args | grep elf32-core-headers) + found_elf_args=$(echo "$kexec_args" | grep elf32-core-headers) if [[ -n "$found_elf_args" ]] then dwarn "Warning: elf32-core-headers overrides correct elf64 setting" @@ -602,14 +602,14 @@ prepare_kexec_args() kexec_args="$kexec_args --elf64-core-headers" fi else - found_elf_args=$(echo $kexec_args | grep elf64-core-headers) + found_elf_args=$(echo "$kexec_args" | grep elf64-core-headers) if [[ -z "$found_elf_args" ]] then kexec_args="$kexec_args --elf32-core-headers" fi fi fi - echo $kexec_args + echo "$kexec_args" } # @@ -641,7 +641,7 @@ prepare_kdump_bootinfo() for dir in $boot_dirlist; do for img in $boot_imglist; do if [[ -f "$dir/$img" ]]; then - KDUMP_KERNEL=$(echo $dir/$img | tr -s '/') + KDUMP_KERNEL=$(echo "$dir/$img" | tr -s '/') break 2 fi done @@ -653,7 +653,7 @@ prepare_kdump_bootinfo() fi # Set KDUMP_BOOTDIR to where kernel image is stored - KDUMP_BOOTDIR=$(dirname $KDUMP_KERNEL) + KDUMP_BOOTDIR=$(dirname "$KDUMP_KERNEL") # Default initrd should just stay aside of kernel image, try to find it in KDUMP_BOOTDIR boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" @@ -694,7 +694,7 @@ get_watchdog_drvs() # device/modalias will return driver of this device [[ -f "$_dir/device/modalias" ]] || continue _drv=$(< "$_dir/device/modalias") - _drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R $_drv 2>/dev/null) + _drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R "$_drv" 2>/dev/null) for i in $_drv; do if ! [[ " $_wdtdrvs " == *" $i "* ]]; then _wdtdrvs="$_wdtdrvs $i" @@ -702,7 +702,7 @@ get_watchdog_drvs() done done - echo $_wdtdrvs + echo "$_wdtdrvs" } # @@ -711,7 +711,7 @@ get_watchdog_drvs() # Store the final result in global $KDUMP_COMMANDLINE. prepare_cmdline() { - local cmdline id + local cmdline id arg if [[ -z "$1" ]]; then cmdline=$(/dev/null || return 1 + readelf -h "$1" &>/dev/null || return 1 } get_vmlinux_size() @@ -910,14 +912,14 @@ try_decompress() # Try to find the header ($1) and decompress from here for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2") do - if ! type -P $3 > /dev/null; then + if ! type -P "$3" > /dev/null; then ddebug "Signiature detected but '$3' is missing, skip this decompressor" break fi pos=${pos%%:*} - tail -c+$pos "$img" | $3 > $5 2> /dev/null - if check_vmlinux $5; then + tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null + if check_vmlinux "$5"; then ddebug "Kernel is extracted with '$3'" return 0 fi @@ -931,22 +933,22 @@ get_kernel_size() { # Prepare temp files: local img=$1 tmp=$(mktemp /tmp/vmlinux-XXX) - trap "rm -f $tmp" 0 + trap 'rm -f "$tmp"' 0 # Try to check if it's a vmlinux already - check_vmlinux $img && get_vmlinux_size $img && return 0 + check_vmlinux "$img" && get_vmlinux_size "$img" && return 0 # That didn't work, so retry after decompression. - try_decompress '\037\213\010' xy gunzip $img $tmp || \ - try_decompress '\3757zXZ\000' abcde unxz $img $tmp || \ - try_decompress 'BZh' xy bunzip2 $img $tmp || \ - try_decompress '\135\0\0\0' xxx unlzma $img $tmp || \ - try_decompress '\211\114\132' xy 'lzop -d' $img $tmp || \ - try_decompress '\002!L\030' xxx 'lz4 -d' $img $tmp || \ - try_decompress '(\265/\375' xxx unzstd $img $tmp + try_decompress '\037\213\010' xy gunzip "$img" "$tmp" || \ + try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" || \ + try_decompress 'BZh' xy bunzip2 "$img" "$tmp" || \ + try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" || \ + try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" || \ + try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" || \ + try_decompress '(\265/\375' xxx unzstd "$img" "$tmp" # Finally check for uncompressed images or objects: - [[ $? -eq 0 ]] && get_vmlinux_size $tmp && return 0 + [[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0 # Fallback to use iomem local _size=0 _seg From 20089dddd5b2dcf233483e3b5b8142f33e5ab7f1 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 8 Sep 2021 03:48:19 +0800 Subject: [PATCH 144/454] kdump-lib.sh: declare and assign separately See: https://github.com/koalaman/shellcheck/wiki/SC2155 Signed-off-by: Kairui Song --- kdump-lib.sh | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 64c6e4f..ac36592 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -158,12 +158,15 @@ get_kdump_targets() # part is the bind mounted directory which quotes by bracket "[]". get_bind_mount_source() { - local _mnt=$(df "$1" | tail -1 | awk '{print $NF}') - local _path=${1#$_mnt} + local _mnt _path _src _opt _fstype + local _fsroot _src_nofsroot - local _src=$(get_mount_info SOURCE target "$_mnt" -f) - local _opt=$(get_mount_info OPTIONS target "$_mnt" -f) - local _fstype=$(get_mount_info FSTYPE target "$_mnt" -f) + _mnt=$(df "$1" | tail -1 | awk '{print $NF}') + _path=${1#$_mnt} + + _src=$(get_mount_info SOURCE target "$_mnt" -f) + _opt=$(get_mount_info OPTIONS target "$_mnt" -f) + _fstype=$(get_mount_info FSTYPE target "$_mnt" -f) # bind mount in fstab if [[ -d "$_src" ]] && [[ "$_fstype" = none ]] && (echo "$_opt" | grep -q "\bbind\b"); then @@ -171,12 +174,12 @@ get_bind_mount_source() fi # direct mount - local _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f) + _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f) if [[ $_src_nofsroot = "$_src" ]]; then echo "$_mnt$_path" && return fi - local _fsroot=${_src#${_src_nofsroot}[} + _fsroot=${_src#${_src_nofsroot}[} _fsroot=${_fsroot%]} _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) @@ -199,8 +202,9 @@ get_mntopt_from_target() # $1: kdump target device get_kdump_mntpoint_from_target() { - local _mntpoint=$(get_mntpoint_from_target "$1") + local _mntpoint + _mntpoint=$(get_mntpoint_from_target "$1") # mount under /sysroot if dump to root disk or mount under # mount under /kdumproot if dump target is not mounted in first kernel # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel. @@ -254,8 +258,9 @@ get_remote_host() is_hostname() { - local _hostname=$(echo "$1" | grep ":") + local _hostname + _hostname=$(echo "$1" | grep ":") if [[ -n "$_hostname" ]]; then return 1 fi @@ -369,7 +374,7 @@ get_ifcfg_nmcli() # $1: netdev name get_ifcfg_legacy() { - local ifcfg_file + local ifcfg_file hwaddr ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}" [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return @@ -377,7 +382,7 @@ get_ifcfg_legacy() ifcfg_file=$(get_ifcfg_by_name "${1}") [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return - local hwaddr=$(get_hwaddr "${1}") + hwaddr=$(get_hwaddr "${1}") if [[ -n "$hwaddr" ]]; then ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}") [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return @@ -621,7 +626,7 @@ prepare_kexec_args() # prepare_kdump_bootinfo() { - local boot_imglist boot_dirlist boot_initrdlist + local boot_img boot_imglist boot_dirlist boot_initrdlist local machine_id if [[ -z "$KDUMP_KERNELVER" ]]; then @@ -633,7 +638,7 @@ prepare_kdump_bootinfo() boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG" # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format - local boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)" + boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)" if [[ -n "$boot_img" ]]; then boot_imglist="$boot_img $boot_imglist" fi @@ -855,9 +860,11 @@ kdump_get_arch_recommend_size() # $1: the block device to be checked in maj:min format get_luks_crypt_dev() { + local _type + [[ -b /dev/block/$1 ]] || return 1 - local _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE") + _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE") [[ $_type == "crypto_LUKS" ]] && echo "$1" for _x in "/sys/dev/block/$1/slaves/"*; do @@ -932,7 +939,9 @@ try_decompress() get_kernel_size() { # Prepare temp files: - local img=$1 tmp=$(mktemp /tmp/vmlinux-XXX) + local tmp img=$1 + + tmp=$(mktemp /tmp/vmlinux-XXX) trap 'rm -f "$tmp"' 0 # Try to check if it's a vmlinux already From 4cdce1f48915c1f46ef01af4b50d000c5858cbdf Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 14 Sep 2021 03:09:30 +0800 Subject: [PATCH 145/454] kdump-lib.sh: reformat with shfmt This is a batch update done with: shfmt -s -w kdump-lib.sh Clean up code style and reduce code base size, no behaviour change. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-lib.sh | 1110 +++++++++++++++++++++++++------------------------- 1 file changed, 557 insertions(+), 553 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index ac36592..2e2775c 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -11,137 +11,141 @@ FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" is_fadump_capable() { - # Check if firmware-assisted dump is enabled - # if no, fallback to kdump check - if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then - rc=$(<$FADUMP_ENABLED_SYS_NODE) - [[ $rc -eq 1 ]] && return 0 - fi - return 1 + # Check if firmware-assisted dump is enabled + # if no, fallback to kdump check + if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then + rc=$(< $FADUMP_ENABLED_SYS_NODE) + [[ $rc -eq 1 ]] && return 0 + fi + return 1 } -is_squash_available() { - for kmodule in squashfs overlay loop; do - if [[ -z "$KDUMP_KERNELVER" ]]; then - modprobe --dry-run $kmodule &>/dev/null || return 1 - else - modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &>/dev/null || return 1 - fi - done +is_squash_available() +{ + for kmodule in squashfs overlay loop; do + if [[ -z $KDUMP_KERNELVER ]]; then + modprobe --dry-run $kmodule &> /dev/null || return 1 + else + modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &> /dev/null || return 1 + fi + done } -perror_exit() { - derror "$@" - exit 1 +perror_exit() +{ + derror "$@" + exit 1 } # Check if fence kdump is configured in Pacemaker cluster is_pcs_fence_kdump() { - # no pcs or fence_kdump_send executables installed? - type -P pcs > /dev/null || return 1 - [[ -x $FENCE_KDUMP_SEND ]] || return 1 + # no pcs or fence_kdump_send executables installed? + type -P pcs > /dev/null || return 1 + [[ -x $FENCE_KDUMP_SEND ]] || return 1 - # fence kdump not configured? - (pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1 + # fence kdump not configured? + (pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1 } # Check if fence_kdump is configured using kdump options is_generic_fence_kdump() { - [[ -x $FENCE_KDUMP_SEND ]] || return 1 + [[ -x $FENCE_KDUMP_SEND ]] || return 1 - [[ $(kdump_get_conf_val fence_kdump_nodes) ]] + [[ $(kdump_get_conf_val fence_kdump_nodes) ]] } -to_dev_name() { - local dev="${1//\"/}" +to_dev_name() +{ + local dev="${1//\"/}" - case "$dev" in - UUID=*) - blkid -U "${dev#UUID=}" - ;; - LABEL=*) - blkid -L "${dev#LABEL=}" - ;; - *) - echo "$dev" - esac + case "$dev" in + UUID=*) + blkid -U "${dev#UUID=}" + ;; + LABEL=*) + blkid -L "${dev#LABEL=}" + ;; + *) + echo "$dev" + ;; + esac } is_user_configured_dump_target() { - [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh") ]] || is_mount_in_dracut_args + [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh") ]] || is_mount_in_dracut_args } get_user_configured_dump_disk() { - local _target + local _target - _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw") - [[ -n "$_target" ]] && echo "$_target" && return + _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw") + [[ -n $_target ]] && echo "$_target" && return - _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") - [[ -b "$_target" ]] && echo "$_target" + _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") + [[ -b $_target ]] && echo "$_target" } get_block_dump_target() { - local _target _path + local _target _path - if is_ssh_dump_target || is_nfs_dump_target; then - return - fi + if is_ssh_dump_target || is_nfs_dump_target; then + return + fi - _target=$(get_user_configured_dump_disk) - [[ -n "$_target" ]] && to_dev_name "$_target" && return + _target=$(get_user_configured_dump_disk) + [[ -n $_target ]] && to_dev_name "$_target" && return - # Get block device name from local save path - _path=$(get_save_path) - _target=$(get_target_from_path "$_path") - [[ -b "$_target" ]] && to_dev_name "$_target" + # Get block device name from local save path + _path=$(get_save_path) + _target=$(get_target_from_path "$_path") + [[ -b $_target ]] && to_dev_name "$_target" } is_dump_to_rootfs() { - [[ $(kdump_get_conf_val "failure_action|default") == dump_to_rootfs ]] + [[ $(kdump_get_conf_val "failure_action|default") == dump_to_rootfs ]] } get_failure_action_target() { - local _target + local _target - if is_dump_to_rootfs; then - # Get rootfs device name - _target=$(get_root_fs_device) - [[ -b "$_target" ]] && to_dev_name "$_target" && return - # Then, must be nfs root - echo "nfs" - fi + if is_dump_to_rootfs; then + # Get rootfs device name + _target=$(get_root_fs_device) + [[ -b $_target ]] && to_dev_name "$_target" && return + # Then, must be nfs root + echo "nfs" + fi } # Get kdump targets(including root in case of dump_to_rootfs). get_kdump_targets() { - local _target _root - local kdump_targets + local _target _root + local kdump_targets - _target=$(get_block_dump_target) - if [[ -n "$_target" ]]; then - kdump_targets=$_target - elif is_ssh_dump_target; then - kdump_targets="ssh" - else - kdump_targets="nfs" - fi + _target=$(get_block_dump_target) + if [[ -n $_target ]]; then + kdump_targets=$_target + elif is_ssh_dump_target; then + kdump_targets="ssh" + else + kdump_targets="nfs" + fi - # Add the root device if dump_to_rootfs is specified. - _root=$(get_failure_action_target) - if [[ -n "$_root" ]] && [[ "$kdump_targets" != "$_root" ]]; then - kdump_targets="$kdump_targets $_root" - fi + # Add the root device if dump_to_rootfs is specified. + _root=$(get_failure_action_target) + if [[ -n $_root ]] && [[ $kdump_targets != "$_root" ]]; then + kdump_targets="$kdump_targets $_root" + fi - echo "$kdump_targets" + echo "$kdump_targets" } # Return the bind mount source path, return the path itself if it's not bind mounted @@ -158,128 +162,128 @@ get_kdump_targets() # part is the bind mounted directory which quotes by bracket "[]". get_bind_mount_source() { - local _mnt _path _src _opt _fstype - local _fsroot _src_nofsroot + local _mnt _path _src _opt _fstype + local _fsroot _src_nofsroot - _mnt=$(df "$1" | tail -1 | awk '{print $NF}') - _path=${1#$_mnt} + _mnt=$(df "$1" | tail -1 | awk '{print $NF}') + _path=${1#$_mnt} - _src=$(get_mount_info SOURCE target "$_mnt" -f) - _opt=$(get_mount_info OPTIONS target "$_mnt" -f) - _fstype=$(get_mount_info FSTYPE target "$_mnt" -f) + _src=$(get_mount_info SOURCE target "$_mnt" -f) + _opt=$(get_mount_info OPTIONS target "$_mnt" -f) + _fstype=$(get_mount_info FSTYPE target "$_mnt" -f) - # bind mount in fstab - if [[ -d "$_src" ]] && [[ "$_fstype" = none ]] && (echo "$_opt" | grep -q "\bbind\b"); then - echo "$_src$_path" && return - fi + # bind mount in fstab + if [[ -d $_src ]] && [[ $_fstype == none ]] && (echo "$_opt" | grep -q "\bbind\b"); then + echo "$_src$_path" && return + fi - # direct mount - _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f) - if [[ $_src_nofsroot = "$_src" ]]; then - echo "$_mnt$_path" && return - fi + # direct mount + _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f) + if [[ $_src_nofsroot == "$_src" ]]; then + echo "$_mnt$_path" && return + fi - _fsroot=${_src#${_src_nofsroot}[} - _fsroot=${_fsroot%]} - _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) + _fsroot=${_src#${_src_nofsroot}[} + _fsroot=${_fsroot%]} + _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) - # for btrfs, _fsroot will also contain the subvol value as well, strip it - if [[ "$_fstype" = btrfs ]]; then - local _subvol - _subvol=${_opt#*subvol=} - _subvol=${_subvol%,*} - _fsroot=${_fsroot#$_subvol} - fi - echo "$_mnt$_fsroot$_path" + # for btrfs, _fsroot will also contain the subvol value as well, strip it + if [[ $_fstype == btrfs ]]; then + local _subvol + _subvol=${_opt#*subvol=} + _subvol=${_subvol%,*} + _fsroot=${_fsroot#$_subvol} + fi + echo "$_mnt$_fsroot$_path" } get_mntopt_from_target() { - get_mount_info OPTIONS source "$1" -f + get_mount_info OPTIONS source "$1" -f } # Get the path where the target will be mounted in kdump kernel # $1: kdump target device get_kdump_mntpoint_from_target() { - local _mntpoint + local _mntpoint - _mntpoint=$(get_mntpoint_from_target "$1") - # mount under /sysroot if dump to root disk or mount under - # mount under /kdumproot if dump target is not mounted in first kernel - # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel. - # systemd will be in charge to umount it. - if [[ -z "$_mntpoint" ]];then - _mntpoint="/kdumproot" - else - if [[ "$_mntpoint" = "/" ]];then - _mntpoint="/sysroot" - else - _mntpoint="/kdumproot/$_mntpoint" - fi - fi + _mntpoint=$(get_mntpoint_from_target "$1") + # mount under /sysroot if dump to root disk or mount under + # mount under /kdumproot if dump target is not mounted in first kernel + # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel. + # systemd will be in charge to umount it. + if [[ -z $_mntpoint ]]; then + _mntpoint="/kdumproot" + else + if [[ $_mntpoint == "/" ]]; then + _mntpoint="/sysroot" + else + _mntpoint="/kdumproot/$_mntpoint" + fi + fi - # strip duplicated "/" - echo $_mntpoint | tr -s "/" + # strip duplicated "/" + echo $_mntpoint | tr -s "/" } -kdump_get_persistent_dev() { - local dev="${1//\"/}" +kdump_get_persistent_dev() +{ + local dev="${1//\"/}" - case "$dev" in - UUID=*) - dev=$(blkid -U "${dev#UUID=}") - ;; - LABEL=*) - dev=$(blkid -L "${dev#LABEL=}") - ;; - esac - echo $(get_persistent_dev "$dev") + case "$dev" in + UUID=*) + dev=$(blkid -U "${dev#UUID=}") + ;; + LABEL=*) + dev=$(blkid -L "${dev#LABEL=}") + ;; + esac + echo $(get_persistent_dev "$dev") } is_atomic() { - grep -q "ostree" /proc/cmdline + grep -q "ostree" /proc/cmdline } # get ip address or hostname from nfs/ssh config value get_remote_host() { - local _config_val=$1 + local _config_val=$1 - # ipv6 address in kdump.conf is around with "[]", - # factor out the ipv6 address - _config_val=${_config_val#*@} - _config_val=${_config_val%:/*} - _config_val=${_config_val#[} - _config_val=${_config_val%]} - echo "$_config_val" + # ipv6 address in kdump.conf is around with "[]", + # factor out the ipv6 address + _config_val=${_config_val#*@} + _config_val=${_config_val%:/*} + _config_val=${_config_val#[} + _config_val=${_config_val%]} + echo "$_config_val" } is_hostname() { - local _hostname + local _hostname - _hostname=$(echo "$1" | grep ":") - if [[ -n "$_hostname" ]]; then - return 1 - fi - echo "$1" | grep -q "[a-zA-Z]" + _hostname=$(echo "$1" | grep ":") + if [[ -n $_hostname ]]; then + return 1 + fi + echo "$1" | grep -q "[a-zA-Z]" } # Copied from "/etc/sysconfig/network-scripts/network-functions" get_hwaddr() { - if [[ -f "/sys/class/net/$1/address" ]]; then - awk '{ print toupper($0) }' < "/sys/class/net/$1/address" - elif [[ -d "/sys/class/net/$1" ]]; then - LC_ALL="" LANG="" ip -o link show "$1" 2>/dev/null | \ - awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/, + if [[ -f "/sys/class/net/$1/address" ]]; then + awk '{ print toupper($0) }' < "/sys/class/net/$1/address" + elif [[ -d "/sys/class/net/$1" ]]; then + LC_ALL="" LANG="" ip -o link show "$1" 2> /dev/null | + awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/, "\\1", 1)); }' - fi + fi } - # Get value by a field using "nmcli -g" # Usage: get_nmcli_value_by_field # @@ -292,16 +296,16 @@ get_hwaddr() # bond.options "mode=balance-rr" get_nmcli_value_by_field() { - LANG=C nmcli --get-values "$@" + LANG=C nmcli --get-values "$@" } # Get nmcli field value of an connection apath (a D-Bus active connection path) # Usage: get_nmcli_field_by_apath get_nmcli_field_by_conpath() { - local _field=$1 _apath=$2 + local _field=$1 _apath=$2 - get_nmcli_value_by_field "$_field" connection show "$_apath" + get_nmcli_value_by_field "$_field" connection show "$_apath" } # Get nmcli connection apath (a D-Bus active connection path ) by ifname @@ -310,129 +314,133 @@ get_nmcli_field_by_conpath() # $ nmcli connection show $apath get_nmcli_connection_apath_by_ifname() { - local _ifname=$1 + local _ifname=$1 - get_nmcli_value_by_field "GENERAL.CON-PATH" device show "$_ifname" + get_nmcli_value_by_field "GENERAL.CON-PATH" device show "$_ifname" } get_ifcfg_by_device() { - grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1 + grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \ + /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 } get_ifcfg_by_hwaddr() { - grep -E -i -l "^[[:space:]]*HWADDR=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1 + grep -E -i -l "^[[:space:]]*HWADDR=\"*${1}\"*[[:space:]]*$" \ + /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 } get_ifcfg_by_uuid() { - grep -E -i -l "^[[:space:]]*UUID=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1 + grep -E -i -l "^[[:space:]]*UUID=\"*${1}\"*[[:space:]]*$" \ + /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 } get_ifcfg_by_name() { - grep -E -i -l "^[[:space:]]*NAME=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2>/dev/null | head -1 + grep -E -i -l "^[[:space:]]*NAME=\"*${1}\"*[[:space:]]*$" \ + /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 } is_nm_running() { - [[ "$(LANG=C nmcli -t --fields running general status 2>/dev/null)" = "running" ]] + [[ "$(LANG=C nmcli -t --fields running general status 2> /dev/null)" == "running" ]] } is_nm_handling() { - LANG=C nmcli -t --fields device,state dev status 2>/dev/null \ - | grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$" + LANG=C nmcli -t --fields device,state dev status 2> /dev/null | + grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$" } # $1: netdev name get_ifcfg_nmcli() { - local nm_uuid nm_name - local ifcfg_file + local nm_uuid nm_name + local ifcfg_file - # Get the active nmcli config name of $1 - if is_nm_running && is_nm_handling "${1}" ; then - # The configuration "uuid" and "name" generated by nm is wrote to - # the ifcfg file as "UUID=" and "NAME=". - nm_uuid=$(LANG=C nmcli -t --fields uuid,device c show --active 2>/dev/null \ - | grep "${1}" | head -1 | cut -d':' -f1) - nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2>/dev/null \ - | grep "${1}" | head -1 | cut -d':' -f1) - ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}") - [[ -z "${ifcfg_file}" ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}") - fi + # Get the active nmcli config name of $1 + if is_nm_running && is_nm_handling "${1}"; then + # The configuration "uuid" and "name" generated by nm is wrote to + # the ifcfg file as "UUID=" and "NAME=". + nm_uuid=$(LANG=C nmcli -t --fields uuid,device c show --active 2> /dev/null | + grep "${1}" | head -1 | cut -d':' -f1) + nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2> /dev/null | + grep "${1}" | head -1 | cut -d':' -f1) + ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}") + [[ -z ${ifcfg_file} ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}") + fi - echo -n "${ifcfg_file}" + echo -n "${ifcfg_file}" } # $1: netdev name get_ifcfg_legacy() { - local ifcfg_file hwaddr + local ifcfg_file hwaddr - ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}" - [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return + ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}" + [[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return - ifcfg_file=$(get_ifcfg_by_name "${1}") - [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return + ifcfg_file=$(get_ifcfg_by_name "${1}") + [[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return - hwaddr=$(get_hwaddr "${1}") - if [[ -n "$hwaddr" ]]; then - ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}") - [[ -f "${ifcfg_file}" ]] && echo -n "${ifcfg_file}" && return - fi + hwaddr=$(get_hwaddr "${1}") + if [[ -n $hwaddr ]]; then + ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}") + [[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return + fi - ifcfg_file=$(get_ifcfg_by_device "${1}") + ifcfg_file=$(get_ifcfg_by_device "${1}") - echo -n "${ifcfg_file}" + echo -n "${ifcfg_file}" } # $1: netdev name # Return the ifcfg file whole name(including the path) of $1 if any. -get_ifcfg_filename() { - local ifcfg_file +get_ifcfg_filename() +{ + local ifcfg_file - ifcfg_file=$(get_ifcfg_nmcli "${1}") - if [[ -z "${ifcfg_file}" ]]; then - ifcfg_file=$(get_ifcfg_legacy "${1}") - fi + ifcfg_file=$(get_ifcfg_nmcli "${1}") + if [[ -z ${ifcfg_file} ]]; then + ifcfg_file=$(get_ifcfg_legacy "${1}") + fi - echo -n "${ifcfg_file}" + echo -n "${ifcfg_file}" } # returns 0 when omission of a module is desired in dracut_args # returns 1 otherwise -is_dracut_mod_omitted() { - local dracut_args dracut_mod=$1 +is_dracut_mod_omitted() +{ + local dracut_args dracut_mod=$1 - set -- $(kdump_get_conf_val dracut_args) - while [ $# -gt 0 ]; do - case $1 in - -o|--omit) - [[ " ${2//[^[:alnum:]]/ } " == *" $dracut_mod "* ]] && return 0 - esac - shift - done + set -- $(kdump_get_conf_val dracut_args) + while [ $# -gt 0 ]; do + case $1 in + -o | --omit) + [[ " ${2//[^[:alnum:]]/ } " == *" $dracut_mod "* ]] && return 0 + ;; + esac + shift + done - return 1 + return 1 } -is_wdt_active() { - local active +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 + [[ -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 @@ -440,45 +448,45 @@ is_wdt_active() { # its correctness). is_mount_in_dracut_args() { - [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] + [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] } check_crash_mem_reserved() { - local mem_reserved + local mem_reserved - mem_reserved=$( [] ... [] @@ -486,17 +494,17 @@ check_current_kdump_status() # For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists. remove_cmdline_param() { - local cmdline=$1 - shift + local cmdline=$1 + shift - for arg in "$@"; do - cmdline=$(echo "$cmdline" | \ - sed -e "s/\b$arg=[^ ]*//g" \ - -e "s/^$arg\b//g" \ - -e "s/[[:space:]]$arg\b//g" \ - -e "s/\s\+/ /g") - done - echo "$cmdline" + for arg in "$@"; do + cmdline=$(echo "$cmdline" | + sed -e "s/\b$arg=[^ ]*//g" \ + -e "s/^$arg\b//g" \ + -e "s/[[:space:]]$arg\b//g" \ + -e "s/\s\+/ /g") + done + echo "$cmdline" } # @@ -505,12 +513,12 @@ remove_cmdline_param() # get_bootcpu_apicid() { - awk ' \ + awk ' \ BEGIN { CPU = "-1"; } \ $1=="processor" && $2==":" { CPU = $NF; } \ CPU=="0" && /^apicid/ { print $NF; } \ - ' \ - /proc/cpuinfo + ' \ + /proc/cpuinfo } # @@ -519,22 +527,22 @@ get_bootcpu_apicid() # append_cmdline() { - local cmdline=$1 - local newstr=${cmdline/$2/""} + local cmdline=$1 + local newstr=${cmdline/$2/""} - # unchanged str implies argument wasn't there - if [[ "$cmdline" == "$newstr" ]]; then - cmdline="${cmdline} ${2}=${3}" - fi + # unchanged str implies argument wasn't there + if [[ $cmdline == "$newstr" ]]; then + cmdline="${cmdline} ${2}=${3}" + fi - echo "$cmdline" + echo "$cmdline" } # This function check iomem and determines if we have more than # 4GB of ram available. Returns 1 if we do, 0 if we dont need_64bit_headers() { - return "$(tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); + return "$(tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }')" } @@ -549,39 +557,39 @@ need_64bit_headers() # Assume efivars is mounted at /sys/firmware/efi/efivars. is_secure_boot_enforced() { - local secure_boot_file setup_mode_file - local secure_boot_byte setup_mode_byte + local secure_boot_file setup_mode_file + local secure_boot_byte setup_mode_byte - # On powerpc, secure boot is enforced if: - # host secure boot: /ibm,secure-boot/os-secureboot-enforcing DT property exists - # guest secure boot: /ibm,secure-boot >= 2 - if [[ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]]; then + # On powerpc, secure boot is enforced if: + # host secure boot: /ibm,secure-boot/os-secureboot-enforcing DT property exists + # guest secure boot: /ibm,secure-boot >= 2 + if [[ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]]; then return 0 - fi - if [[ -f /proc/device-tree/ibm,secure-boot ]] && \ - [[ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]]; then + fi + if [[ -f /proc/device-tree/ibm,secure-boot ]] && + [[ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]]; then return 0 - fi + fi - # Detect secure boot on x86 and arm64 - secure_boot_file=$(find /sys/firmware/efi/efivars -name "SecureBoot-*" 2>/dev/null) - setup_mode_file=$(find /sys/firmware/efi/efivars -name "SetupMode-*" 2>/dev/null) + # Detect secure boot on x86 and arm64 + secure_boot_file=$(find /sys/firmware/efi/efivars -name "SecureBoot-*" 2> /dev/null) + setup_mode_file=$(find /sys/firmware/efi/efivars -name "SetupMode-*" 2> /dev/null) - if [[ -f "$secure_boot_file" ]] && [[ -f "$setup_mode_file" ]]; then - secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' "$secure_boot_file" | cut -d' ' -f 5) - setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' "$setup_mode_file" | cut -d' ' -f 5) + if [[ -f $secure_boot_file ]] && [[ -f $setup_mode_file ]]; then + secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' "$secure_boot_file" | cut -d' ' -f 5) + setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' "$setup_mode_file" | cut -d' ' -f 5) - if [[ "$secure_boot_byte" = "1" ]] && [[ "$setup_mode_byte" = "0" ]]; then - return 0 - fi - fi + if [[ $secure_boot_byte == "1" ]] && [[ $setup_mode_byte == "0" ]]; then + return 0 + fi + fi - # Detect secure boot on s390x - if [[ -e "/sys/firmware/ipl/secure" && "$( initramfs-5.7.9-200.fc32.x86_64kdump.img - # initrd => initrdkdump - if [[ -z "$defaut_initrd_base" ]]; then - kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img - elif [[ $defaut_initrd_base == *.* ]]; then - kdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.} - else - kdump_initrd_base=${defaut_initrd_base}kdump - fi + # Create kdump initrd basename from default initrd basename + # initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img + # initrd => initrdkdump + if [[ -z $defaut_initrd_base ]]; then + kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img + elif [[ $defaut_initrd_base == *.* ]]; then + kdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.} + else + kdump_initrd_base=${defaut_initrd_base}kdump + fi - # Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable - if [[ ! -w "$KDUMP_BOOTDIR" ]];then - var_target_initrd_dir="/var/lib/kdump" - mkdir -p "$var_target_initrd_dir" - KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base" - else - KDUMP_INITRD="$KDUMP_BOOTDIR/$kdump_initrd_base" - fi + # Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable + if [[ ! -w $KDUMP_BOOTDIR ]]; then + var_target_initrd_dir="/var/lib/kdump" + mkdir -p "$var_target_initrd_dir" + KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base" + else + KDUMP_INITRD="$KDUMP_BOOTDIR/$kdump_initrd_base" + fi } get_watchdog_drvs() { - local _wdtdrvs _drv _dir + local _wdtdrvs _drv _dir - for _dir in /sys/class/watchdog/*; do - # device/modalias will return driver of this device - [[ -f "$_dir/device/modalias" ]] || continue - _drv=$(< "$_dir/device/modalias") - _drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R "$_drv" 2>/dev/null) - for i in $_drv; do - if ! [[ " $_wdtdrvs " == *" $i "* ]]; then - _wdtdrvs="$_wdtdrvs $i" - fi - done - done + for _dir in /sys/class/watchdog/*; do + # device/modalias will return driver of this device + [[ -f "$_dir/device/modalias" ]] || continue + _drv=$(< "$_dir/device/modalias") + _drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R "$_drv" 2> /dev/null) + for i in $_drv; do + if ! [[ " $_wdtdrvs " == *" $i "* ]]; then + _wdtdrvs="$_wdtdrvs $i" + fi + done + done - echo "$_wdtdrvs" + echo "$_wdtdrvs" } # @@ -716,143 +720,143 @@ get_watchdog_drvs() # Store the final result in global $KDUMP_COMMANDLINE. prepare_cmdline() { - local cmdline id arg + local cmdline id arg - if [[ -z "$1" ]]; then - cmdline=$(/dev/null) + [[ -z $kernel ]] && kernel=$(uname -r) + ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2> /dev/null) - if [[ -n "$ck_cmdline" ]]; then - ck_cmdline=${ck_cmdline#crashkernel=} - else - arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]') - if [[ "$arch" = "X86_64" ]] || [[ "$arch" = "S390X" ]]; then - ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" - elif [[ "$arch" = "AARCH64" ]]; then - ck_cmdline="2G-:448M" - elif [[ "$arch" = "PPC64LE" ]]; then - if is_fadump_capable; then - ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" - else - ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" - fi - fi - fi + if [[ -n $ck_cmdline ]]; then + ck_cmdline=${ck_cmdline#crashkernel=} + else + arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]') + if [[ $arch == "X86_64" ]] || [[ $arch == "S390X" ]]; then + ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" + elif [[ $arch == "AARCH64" ]]; then + ck_cmdline="2G-:448M" + elif [[ $arch == "PPC64LE" ]]; then + if is_fadump_capable; then + ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" + else + ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" + fi + fi + fi - ck_cmdline=${ck_cmdline//-:/-102400T:} - sys_mem=$(get_system_size) + ck_cmdline=${ck_cmdline//-:/-102400T:} + sys_mem=$(get_system_size) - get_recommend_size "$sys_mem" "$ck_cmdline" + get_recommend_size "$sys_mem" "$ck_cmdline" } # Print all underlying crypt devices of a block device @@ -860,18 +864,18 @@ kdump_get_arch_recommend_size() # $1: the block device to be checked in maj:min format get_luks_crypt_dev() { - local _type + local _type - [[ -b /dev/block/$1 ]] || return 1 + [[ -b /dev/block/$1 ]] || return 1 - _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE") - [[ $_type == "crypto_LUKS" ]] && echo "$1" + _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE") + [[ $_type == "crypto_LUKS" ]] && echo "$1" - for _x in "/sys/dev/block/$1/slaves/"*; do - [[ -f $_x/dev ]] || continue - [[ $_x/subsystem -ef /sys/class/block ]] || continue - get_luks_crypt_dev "$(< "$_x/dev")" - done + for _x in "/sys/dev/block/$1/slaves/"*; do + [[ -f $_x/dev ]] || continue + [[ $_x/subsystem -ef /sys/class/block ]] || continue + get_luks_crypt_dev "$(< "$_x/dev")" + done } # kdump_get_maj_min @@ -879,90 +883,90 @@ get_luks_crypt_dev() # Example: # $ get_maj_min /dev/sda2 # 8:2 -kdump_get_maj_min() { - local _majmin - _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)" - printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" +kdump_get_maj_min() +{ + local _majmin + _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)" + printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" } get_all_kdump_crypt_dev() { - local _dev + local _dev - for _dev in $(get_block_dump_target); do - get_luks_crypt_dev "$(kdump_get_maj_min "$_dev")" - done + for _dev in $(get_block_dump_target); do + get_luks_crypt_dev "$(kdump_get_maj_min "$_dev")" + done } check_vmlinux() { - # Use readelf to check if it's a valid ELF - readelf -h "$1" &>/dev/null || return 1 + # Use readelf to check if it's a valid ELF + readelf -h "$1" &> /dev/null || return 1 } get_vmlinux_size() { - local size=0 _msize + local size=0 _msize - while read -r _msize; do - size=$(( size + _msize )) - done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2>/dev/stderr)" + while read -r _msize; do + size=$((size + _msize)) + done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2> /dev/stderr)" - echo $size + echo $size } try_decompress() { - # The obscure use of the "tr" filter is to work around older versions of - # "grep" that report the byte offset of the line instead of the pattern. + # The obscure use of the "tr" filter is to work around older versions of + # "grep" that report the byte offset of the line instead of the pattern. - # Try to find the header ($1) and decompress from here - for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2") - do - if ! type -P "$3" > /dev/null; then - ddebug "Signiature detected but '$3' is missing, skip this decompressor" - break - fi + # Try to find the header ($1) and decompress from here + for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"); do + if ! type -P "$3" > /dev/null; then + ddebug "Signiature detected but '$3' is missing, skip this decompressor" + break + fi - pos=${pos%%:*} - tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null - if check_vmlinux "$5"; then - ddebug "Kernel is extracted with '$3'" - return 0 - fi - done + pos=${pos%%:*} + tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null + if check_vmlinux "$5"; then + ddebug "Kernel is extracted with '$3'" + return 0 + fi + done - return 1 + return 1 } # Borrowed from linux/scripts/extract-vmlinux get_kernel_size() { - # Prepare temp files: - local tmp img=$1 + # Prepare temp files: + local tmp img=$1 - tmp=$(mktemp /tmp/vmlinux-XXX) - trap 'rm -f "$tmp"' 0 + tmp=$(mktemp /tmp/vmlinux-XXX) + trap 'rm -f "$tmp"' 0 - # Try to check if it's a vmlinux already - check_vmlinux "$img" && get_vmlinux_size "$img" && return 0 + # Try to check if it's a vmlinux already + check_vmlinux "$img" && get_vmlinux_size "$img" && return 0 - # That didn't work, so retry after decompression. - try_decompress '\037\213\010' xy gunzip "$img" "$tmp" || \ - try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" || \ - try_decompress 'BZh' xy bunzip2 "$img" "$tmp" || \ - try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" || \ - try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" || \ - try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" || \ - try_decompress '(\265/\375' xxx unzstd "$img" "$tmp" + # That didn't work, so retry after decompression. + try_decompress '\037\213\010' xy gunzip "$img" "$tmp" || + try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" || + try_decompress 'BZh' xy bunzip2 "$img" "$tmp" || + try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" || + try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" || + try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" || + try_decompress '(\265/\375' xxx unzstd "$img" "$tmp" - # Finally check for uncompressed images or objects: - [[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0 + # Finally check for uncompressed images or objects: + [[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0 - # Fallback to use iomem - local _size=0 _seg - while read -r _seg; do - _size=$(( _size + 0x${_seg#*-} - 0x${_seg%-*} )) - done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)" - echo $_size + # Fallback to use iomem + local _size=0 _seg + while read -r _seg; do + _size=$((_size + 0x${_seg#*-} - 0x${_seg%-*})) + done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)" + echo $_size } From 8cd57e5565142553b1fe739afe90723359b18498 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 11 Aug 2021 19:19:59 +0800 Subject: [PATCH 146/454] kdump-logger.sh: make it POSIX compatible Refactor to remove some bash only syntax. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- kdump-logger.sh | 117 +++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 56 deletions(-) diff --git a/kdump-logger.sh b/kdump-logger.sh index 370e5e8..98c4eea 100755 --- a/kdump-logger.sh +++ b/kdump-logger.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # This comes from the dracut-logger.sh # @@ -53,11 +53,12 @@ fi # get_kdump_loglvl() { - (type -p getarg) && kdump_sysloglvl=$(getarg rd.kdumploglvl) + [ -f /lib/dracut-lib.sh ] && kdump_sysloglvl=$(getarg rd.kdumploglvl) [ -z "$kdump_sysloglvl" ] && return 1; - (type -p isdigit) && isdigit $kdump_sysloglvl - [ $? -ne 0 ] && return 1; + if [ -f /lib/dracut-lib.sh ] && ! isdigit "$kdump_sysloglvl"; then + return 1 + fi return 0 } @@ -83,11 +84,10 @@ check_loglvl() # @retval 0 on success. # dlog_init() { - local ret=0; local errmsg + ret=0 if [ -s /proc/vmcore ];then - get_kdump_loglvl - if [ $? -ne 0 ];then + if ! get_kdump_loglvl; then logger -t "kdump[$$]" -p warn -- "Kdump is using the default log level(3)." kdump_sysloglvl=3 fi @@ -104,8 +104,7 @@ dlog_init() { [ -z "$kdump_kmsgloglvl" ] && kdump_kmsgloglvl=0 for loglvl in "$kdump_stdloglvl" "$kdump_kmsgloglvl" "$kdump_sysloglvl"; do - check_loglvl "$loglvl" - if [ $? -ne 0 ]; then + if ! check_loglvl "$loglvl"; then echo "Illegal log level: $kdump_stdloglvl $kdump_kmsgloglvl $kdump_sysloglvl" return 1 fi @@ -114,21 +113,21 @@ dlog_init() { # Skip initialization if it's already done. [ -n "$kdump_maxloglvl" ] && return 0 - if [[ $UID -ne 0 ]]; then + if [ "$UID" -ne 0 ]; then kdump_kmsgloglvl=0 kdump_sysloglvl=0 fi - if [[ $kdump_sysloglvl -gt 0 ]]; then - if [[ -d /run/systemd/journal ]] \ - && type -P systemd-cat &>/dev/null \ - && systemctl --quiet is-active systemd-journald.socket &>/dev/null; then + if [ "$kdump_sysloglvl" -gt 0 ]; then + if [ -d /run/systemd/journal ] \ + && systemd-cat --version 1>/dev/null 2>&1 \ + && systemctl --quiet is-active systemd-journald.socket 1>/dev/null 2>&1; then readonly _systemdcatfile="/var/tmp/systemd-cat" - mkfifo "$_systemdcatfile" &>/dev/null + mkfifo "$_systemdcatfile" 1>/dev/null 2>&1 readonly _dlogfd=15 systemd-cat -t 'kdump' --level-prefix=true <"$_systemdcatfile" & exec 15>"$_systemdcatfile" - elif ! [ -S /dev/log -a -w /dev/log ] || ! command -v logger >/dev/null; then + elif ! [ -S /dev/log ] && [ -w /dev/log ] || ! command -v logger >/dev/null; then # We cannot log to syslog, so turn this facility off. kdump_kmsgloglvl=$kdump_sysloglvl kdump_sysloglvl=0 @@ -137,31 +136,31 @@ dlog_init() { fi fi - local lvl; local maxloglvl_l=0 - for lvl in $kdump_stdloglvl $kdump_sysloglvl $kdump_kmsgloglvl; do - [[ $lvl -gt $maxloglvl_l ]] && maxloglvl_l=$lvl + kdump_maxloglvl=0 + for _dlog_lvl in $kdump_stdloglvl $kdump_sysloglvl $kdump_kmsgloglvl; do + [ $_dlog_lvl -gt $kdump_maxloglvl ] && kdump_maxloglvl=$_dlog_lvl done - readonly kdump_maxloglvl=$maxloglvl_l + readonly kdump_maxloglvl export kdump_maxloglvl - if [[ $kdump_stdloglvl -lt 4 ]] && [[ $kdump_kmsgloglvl -lt 4 ]] && [[ $kdump_sysloglvl -lt 4 ]]; then + if [ $kdump_stdloglvl -lt 4 ] && [ $kdump_kmsgloglvl -lt 4 ] && [ $kdump_sysloglvl -lt 4 ]; then unset ddebug ddebug() { :; }; fi - if [[ $kdump_stdloglvl -lt 3 ]] && [[ $kdump_kmsgloglvl -lt 3 ]] && [[ $kdump_sysloglvl -lt 3 ]]; then + if [ $kdump_stdloglvl -lt 3 ] && [ $kdump_kmsgloglvl -lt 3 ] && [ $kdump_sysloglvl -lt 3 ]; then unset dinfo dinfo() { :; }; fi - if [[ $kdump_stdloglvl -lt 2 ]] && [[ $kdump_kmsgloglvl -lt 2 ]] && [[ $kdump_sysloglvl -lt 2 ]]; 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 1 ]] && [[ $kdump_kmsgloglvl -lt 1 ]] && [[ $kdump_sysloglvl -lt 1 ]]; then + if [ $kdump_stdloglvl -lt 1 ] && [ $kdump_kmsgloglvl -lt 1 ] && [ $kdump_sysloglvl -lt 1 ]; then unset derror derror() { :; }; fi @@ -173,7 +172,7 @@ dlog_init() { ## @brief Converts numeric level to logger priority defined by POSIX.2. # -# @param lvl Numeric logging level in range from 1 to 4. +# @param $1: 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. @@ -189,7 +188,7 @@ _lvl2syspri() { ## @brief Converts logger numeric level to syslog log level # -# @param lvl Numeric logging level in range from 1 to 4. +# @param $1: 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 @@ -209,27 +208,25 @@ _lvl2syspri() { # # @see /usr/include/sys/syslog.h _dlvl2syslvl() { - local lvl - case "$1" in - 1) lvl=3;; - 2) lvl=4;; - 3) lvl=6;; - 4) lvl=7;; + 1) set -- 3;; + 2) set -- 4;; + 3) set -- 6;; + 4) set -- 7;; *) return 1;; esac # 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)) + echo $((24 + $1)) } ## @brief Prints to stderr, to syslog and/or /dev/kmsg given message with # given level (priority). # -# @param lvl Numeric logging level. -# @param msg Message. +# @param $1: Numeric logging level. +# @param $2: Message. # @retval 0 It's always returned, even if logging failed. # # @note This function is not supposed to be called manually. Please use @@ -251,27 +248,24 @@ _dlvl2syslvl() { # - @c INFO to @c info # - @c DEBUG to @c debug _do_dlog() { - local lvl="$1"; shift - local msg="$*" + [ "$1" -le $kdump_stdloglvl ] && printf -- 'kdump: %s\n' "$2" >&2 - [[ $lvl -le $kdump_stdloglvl ]] && printf -- 'kdump: %s\n' "$msg" >&2 - - if [[ $lvl -le $kdump_sysloglvl ]]; then - if [[ "$_dlogfd" ]]; then - printf -- "<%s>%s\n" "$(($(_dlvl2syslvl $lvl) & 7))" "$msg" >&$_dlogfd + if [ "$1" -le $kdump_sysloglvl ]; then + if [ "$_dlogfd" ]; then + printf -- "<%s>%s\n" "$(($(_dlvl2syslvl "$1") & 7))" "$2" 1>&$_dlogfd else - logger -t "kdump[$$]" -p $(_lvl2syspri $lvl) -- "$msg" + logger -t "kdump[$$]" -p "$(_lvl2syspri "$1")" -- "$2" fi fi - [[ $lvl -le $kdump_kmsgloglvl ]] && \ - echo "<$(_dlvl2syslvl $lvl)>kdump[$$] $msg" >/dev/kmsg + [ "$1" -le $kdump_kmsgloglvl ] && \ + echo "<$(_dlvl2syslvl "$1")>kdump[$$] $2" >/dev/kmsg } ## @brief Internal helper function for _do_dlog() # -# @param lvl Numeric logging level. -# @param msg Message. +# @param $1: Numeric logging level. +# @param $2 [...]: Message. # @retval 0 It's always returned, even if logging failed. # # @note This function is not supposed to be called manually. Please use @@ -286,12 +280,13 @@ _do_dlog() { # echo "This is a warning" | dwarn dlog() { [ -z "$kdump_maxloglvl" ] && return 0 - [[ $1 -le $kdump_maxloglvl ]] || return 0 + [ "$1" -le "$kdump_maxloglvl" ] || return 0 - if [[ $# -gt 1 ]]; then - _do_dlog "$@" + if [ $# -gt 1 ]; then + _dlog_lvl=$1; shift + _do_dlog "$_dlog_lvl" "$*" else - while read line || [ -n "$line" ]; do + while read -r line || [ -n "$line" ]; do _do_dlog "$1" "$line" done fi @@ -304,7 +299,9 @@ dlog() { ddebug() { set +x dlog 4 "$@" - [ -n "$debug" ] && set -x || : + if [ -n "$debug" ]; then + set -x + fi } ## @brief Logs message at INFO level (3) @@ -314,7 +311,9 @@ ddebug() { dinfo() { set +x dlog 3 "$@" - [ -n "$debug" ] && set -x || : + if [ -n "$debug" ]; then + set -x + fi } ## @brief Logs message at WARN level (2) @@ -324,7 +323,9 @@ dinfo() { dwarn() { set +x dlog 2 "$@" - [ -n "$debug" ] && set -x || : + if [ -n "$debug" ]; then + set -x + fi } ## @brief It's an alias to dwarn() function. @@ -334,7 +335,9 @@ dwarn() { dwarning() { set +x dwarn "$@" - [ -n "$debug" ] && set -x || : + if [ -n "$debug" ]; then + set -x + fi } ## @brief Logs message at ERROR level (1) @@ -344,5 +347,7 @@ dwarning() { derror() { set +x dlog 1 "$@" - [ -n "$debug" ] && set -x || : + if [ -n "$debug" ]; then + set -x + fi } From 4b4d045b8c0a7d7bf9d09b5b29bc81885e63ed2b Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 11 Aug 2021 19:55:19 +0800 Subject: [PATCH 147/454] mkdumprd: allow using dash All non-POSIX syntax in second kernel are gone, tested on Fedora 34 with latest dracut, dash now works fine. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- mkdumprd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdumprd b/mkdumprd index eebbbe1..c6cb001 100644 --- a/mkdumprd +++ b/mkdumprd @@ -27,7 +27,7 @@ SAVE_PATH=$(get_save_path) OVERRIDE_RESETTABLE=0 extra_modules="" -dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump") +dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth resume ifcfg earlykdump") MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." From ee337c6f497a92a12848a85dcce468c1a4bcd14f Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 13 Sep 2021 03:38:14 +0800 Subject: [PATCH 148/454] Add header comment for POSIX compliant scripts To make things cleaner and more human readable, add a short comment for the POSIX scripts. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-kdump.sh | 4 ++-- kdump-lib-initramfs.sh | 4 ++-- kdump-logger.sh | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 969ea94..b69bc98 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# The main kdump routine in capture kernel -# +# The main kdump routine in capture kernel, bash may not be the +# default shell. Any code added must be POSIX compliant. . /lib/dracut-lib.sh . /lib/kdump-logger.sh diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 0cdb465..c1fd75f 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# Function and variables used in initramfs environment, POSIX compatible -# +# The code in this file will be used in initramfs environment, bash may +# not be the default shell. Any code added must be POSIX compliant. DEFAULT_PATH="/var/crash/" KDUMP_CONFIG_FILE="/etc/kdump.conf" diff --git a/kdump-logger.sh b/kdump-logger.sh index 98c4eea..3fd433d 100755 --- a/kdump-logger.sh +++ b/kdump-logger.sh @@ -34,6 +34,8 @@ # 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! # +# The code in this file might be run in an environment without bash. +# Any code added must be POSIX compliant. # Define vairables for the log levels in this module. kdump_stdloglvl="" From 4c39ad9a0c9808a9b791a3e446d0b209ceccdc5e Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 13 Sep 2021 16:40:25 +0800 Subject: [PATCH 149/454] dracut-early-kdump.sh: make it POSIX compatible Refactor and remove bash only syntax. Signed-off-by: Kairui Song Acked-by: Philipp Rudo --- dracut-early-kdump.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh index 129841e..45ee6dc 100755 --- a/dracut-early-kdump.sh +++ b/dracut-early-kdump.sh @@ -14,9 +14,8 @@ EARLY_KEXEC_ARGS="" . /lib/kdump-lib.sh . /lib/kdump-logger.sh -#initiate the kdump logger -dlog_init -if [ $? -ne 0 ]; then +# initiate the kdump logger +if ! dlog_init; then echo "failed to initiate the kdump logger." exit 1 fi @@ -30,8 +29,7 @@ prepare_parameters() early_kdump_load() { - check_kdump_feasibility - if [ $? -ne 0 ]; then + if ! check_kdump_feasibility; then return 1 fi @@ -40,8 +38,7 @@ early_kdump_load() return 1 fi - check_current_kdump_status - if [ $? == 0 ]; then + if check_current_kdump_status; then return 1 fi @@ -61,10 +58,9 @@ early_kdump_load() --command-line=$EARLY_KDUMP_CMDLINE --initrd=$EARLY_KDUMP_INITRD \ $EARLY_KDUMP_KERNEL" - $KEXEC ${EARLY_KEXEC_ARGS} $standard_kexec_args \ + if $KEXEC $EARLY_KEXEC_ARGS $standard_kexec_args \ --command-line="$EARLY_KDUMP_CMDLINE" \ - --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL - if [ $? == 0 ]; then + --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL; then dinfo "kexec: loaded early-kdump kernel" return 0 else From f6e6aa45518aab0bfbbe8fa4fc94eb3f33036aa1 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Wed, 1 Sep 2021 17:38:50 +0800 Subject: [PATCH 150/454] 92-crashkernel.install: fix exit code The return value of set_ck_kernel or set_grub_ck is wrongly being used as the exit code. This hook should exit with 0 or it may result in unexpected behavior of kernel-install. Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- 92-crashkernel.install | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/92-crashkernel.install b/92-crashkernel.install index de5b2fb..78365ff 100755 --- a/92-crashkernel.install +++ b/92-crashkernel.install @@ -120,8 +120,9 @@ add) if [[ "$boot_ck_cmdline" != "$inst_ck_default" ]] && [[ "$boot_ck_cmdline" == "$boot_ck_default" ]]; then set_kernel_ck "$KERNEL_VERSION" "$inst_ck_default" fi - ;; + exit 0 + ;; remove) # If grub default value is upgraded when this kernel was installed, try downgrade it grub_etc_ck=$(get_grub_etc_ck) @@ -139,5 +140,7 @@ remove) set_grub_ck "$highest_ck_default" fi fi + + exit 0 ;; esac From 6ea954d5182a7cbd42e0888e0c09ef9770eb9e88 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 16 Sep 2021 23:46:28 +0800 Subject: [PATCH 151/454] Release 2.0.22-8 Signed-off-by: Kairui Song --- kexec-tools.spec | 60 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index f71ff81..5dbf625 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.22 -Release: 7%{?dist} +Release: 8%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -382,6 +382,64 @@ done %endif %changelog +* Thu Sep 16 2021 Kairui Song - 2.0.22-8 +- 92-crashkernel.install: fix exit code +- dracut-early-kdump.sh: make it POSIX compatible +- Add header comment for POSIX compliant scripts +- mkdumprd: allow using dash +- kdump-logger.sh: make it POSIX compatible +- kdump-lib.sh: reformat with shfmt +- kdump-lib.sh: declare and assign separately +- kdump-lib.sh: fix variable quoting issue +- kdump-lib.sh: fix a few ambiguous or redundant code +- kdump-lib.sh: fix arithmetic operation syntax +- kdump-lib.sh: remove useless echo and cat +- kdump-lib.sh: rework nmcli related functions +- kdump-lib.sh: replace '[ ]' with '[[ ]]' and get rid of legacy `` +- kdump-lib-initramfs.sh: make it POSIX compatible +- dracut-kdump.sh: reformat with shfmt +- dracut-kdump.sh: make it POSIX compatible +- dracut-kdump.sh: POSIX doesn't support pipefail +- dracut-kdump.sh: Use stat instead of ls to get vmcore size +- dracut-kdump.sh: simplify dump_ssh +- dracut-kdump.sh: remove add_dump_code +- dracut-kdump.sh: don't put KDUMP_SCRIPT_DIR in PATH +- kdump-lib-initramfs.sh: move dump related functions to kdump.sh +- Merge kdump-error-handler.sh into kdump.sh +- kdump-lib-initramfs.sh: prepare to be a POSIX compatible lib +- bash scripts: reformat with shfmt +- bash scripts: declare and assign separately +- bash scripts: fix redundant exit code check +- bash scripts: fix variable quoting issue +- bash scripts: replace '[ ]' with '[[ ]]' for bash scripts +- bash scripts: use $(...) notation instead of legacy `...` +- bash scripts: always use "read -r" +- bash scripts: get rid of unnecessary sed calls +- bash scripts: get rid of expr and let +- bash scripts: remove useless cat +- dracut-module-setup.sh: remove surrounding $() for subshell +- dracut-module-setup.sh: make iscsi check fail early if cd failed +- dracut-module-setup.sh: fix a loop over ls issue +- dracut-module-setup.sh: fix a ambiguous variable reference +- dracut-module-setup.sh: use "*" to expend array as string +- dracut-module-setup.sh: fix _bondoptions wrong references +- dracut-module-setup.sh: remove an unused variable +- dracut-module-setup.sh: rework kdump_get_ip_route_field +- mkfadumprd: make _dracut_isolate_args an array +- mkdumprd: use array to store ssh arguments in mkdir_save_path_ssh +- mkdumprd: remove an awk call in get_fs_size +- mkdumprd: fix multiple issues with get_ssh_size +- mkdumprd: remove some redundant echo +- mkdumprd: make dracut_args an array again +- mkdumprd: use kdump_get_conf_val to read config values +- kdumpctl: refine grep usage +- kdumpctl: fix fragile loops over find output +- kdumpctl: use kdump_get_conf_val to read config values +- kdump-lib.sh: use kdump_get_conf_val to read config values +- kdump-lib.sh: add a config value retrive helper +- kdump-lib.sh: add a config format and read helper +- Add a .editorconfig file + * Tue Aug 31 2021 Adam Williamson - 2.0.22-7 - Don't exit 1 from 92-crashkernel.install if zipl is absent (#1993505) From 294c965ca36927fc082402716d81abc24aa48e59 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 21 Jun 2021 09:18:11 +0800 Subject: [PATCH 152/454] selftest: kill VM reliably by recursively kill children processes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit qemu is launched in nested subprocess and can't be killed by simply killing the job ids, PID Command 2269634 │ ├─ sshd: root [priv] 2269637 │ │ └─ sshd: root@pts/0 2269638 │ │ └─ -bash 2269744 │ │ └─ make test-run V=1 2273117 │ │ └─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273712 │ │ ├─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273714 │ │ │ └─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273737 │ │ │ └─ timeout --foreground 10m /root/kexec-tools-300/tests/scripts/run-qemu -nodefaults -nographic -smp 2 -m 768M -monitor no 2273738 │ │ │ └─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial stdio 2273746 │ │ │ ├─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial std 2273797 │ │ ├─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273798 │ │ │ └─ /bin/bash /root/kexec-tools-300/tests/scripts/run-test.sh 2273831 │ │ │ └─ timeout --foreground 10m /root/kexec-tools-300/tests/scripts/run-qemu -nodefaults -nographic -smp 2 -m 768M -monitor no 2273832 │ │ │ └─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial stdio 2273840 │ │ │ ├─ /usr/bin/qemu-system-x86_64 -enable-kvm -cpu host -nodefaults -nographic -smp 2 -m 768M -monitor none -serial std This led to the error "qemu-system-x86_64: can't bind ip=0.0.0.0 to socket: Address already in use". This patch will kill qemu by killing all the children of the job id. Signed-off-by: Coiby Xu Acked-by: Kairui Song --- tests/scripts/run-test.sh | 33 +++++++++++++++++++++++++++++++-- tests/scripts/test-lib.sh | 3 +-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/scripts/run-test.sh b/tests/scripts/run-test.sh index a68504d..c3e94a3 100755 --- a/tests/scripts/run-test.sh +++ b/tests/scripts/run-test.sh @@ -1,9 +1,38 @@ #!/bin/bash +_kill_if_valid_pid() { + local _pid="$1" + if ps -p "$_pid" > /dev/null + then + kill "$_pid" + fi +} + +_recursive_kill() { + local _pid="$1" + local _children _child + + _children=$(pgrep -P "$_pid") + if [ -n "$_children" ]; then + for _child in $_children + do + _recursive_kill "$_child" + _kill_if_valid_pid "$_child" + done + fi + _kill_if_valid_pid "$_pid" +} + _kill_all_jobs() { local _jobs=$(jobs -r -p) + local _job - [ -n "$_jobs" ] && kill $_jobs + if [ -n "$_jobs" ]; then + for _job in $_jobs + do + _recursive_kill "$_job" + done + fi } trap ' @@ -121,7 +150,7 @@ for test_case in $testcases; do [ $? -ne 0 ] && ret=$(expr $ret + 1) results[$test_case]="$res" - + _kill_all_jobs echo -e "-------- Test finished: $test_case $res --------" for script in $scripts; do script="$testdir/$script" diff --git a/tests/scripts/test-lib.sh b/tests/scripts/test-lib.sh index f8a2249..8b24b2a 100644 --- a/tests/scripts/test-lib.sh +++ b/tests/scripts/test-lib.sh @@ -146,8 +146,7 @@ watch_test_outputs() { ret=$? if [ $ret -ne 255 ]; then - # Test finished, kill VMs - kill $(jobs -p) + # Test finished break 2 fi done From 727251e52efe833b8bb428b5567fca34f8c74b3d Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Tue, 26 Oct 2021 22:03:28 +0800 Subject: [PATCH 153/454] mkdumprd: drop mountaddr/mountproto nfs mount options nfs service will append extra mount options to kernel mount options. Such as mountaddr/mountproto options. These options only represent current mounting details of the 1st kernel, but may not appropriate for the 2nd kernel for the same reason as commit d4f04afa47dea89ad5ca42ad0b2ddc355ce93a64 ("mkdumprd: drop some nfs mount options when reading from kernel"). This patch will remove these options. Signed-off-by: Tao Liu Acked-by: Coiby Xu --- mkdumprd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mkdumprd b/mkdumprd index c6cb001..d87d588 100644 --- a/mkdumprd +++ b/mkdumprd @@ -70,8 +70,8 @@ to_mount() if [[ $_fstype == "nfs"* ]]; then _pdev=$_target - _sed_cmd+='s/,addr=[^,]*//;' - _sed_cmd+='s/,proto=[^,]*//;' + _sed_cmd+='s/,\(mount\)\?addr=[^,]*//g;' + _sed_cmd+='s/,\(mount\)\?proto=[^,]*//g;' _sed_cmd+='s/,clientaddr=[^,]*//;' else # for non-nfs _target converting to use udev persistent name From 6936fbc1b220f35b45b3114f04c6889a2b5e16a2 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 1 Nov 2021 14:13:16 +0800 Subject: [PATCH 154/454] fix broken extra_bins when installing multiple binaries When there more than one binaries, quoting "$val" would make dracut-install treat multiple binaries as one binary. Take "extra_bins /usr/sbin/ping /usr/sbin/ip" as an example, the following error would occur when building initrd, dracut-install: ERROR: installing '/usr/sbin/ping /usr/sbin/ip' dracut: FAILED: /usr/lib/dracut/dracut-install -D /var/tmp/dracut.ODrioZ/initramfs -a /usr/sbin/ping /usr/sbin/ip Fix it by not quoting the variable and bypassing SC2086 shellcheck. Fixes: commit 86538ca6e2e555caa8cdd2bcfcc3c5e94ac6bf58 ("bash scripts: fix variable quoting issue") Acked-by: Tao Liu Signed-off-by: Coiby Xu --- dracut-module-setup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index a5e4b67..1ea0d95 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -686,7 +686,8 @@ kdump_install_conf() { fi ;; kdump_pre | kdump_post | extra_bins) - dracut_install "$_val" + # shellcheck disable=SC2086 + dracut_install $_val ;; core_collector) dracut_install "${_val%%[[:blank:]]*}" From 8b9948df33e48f714409c6fa3af65a72f73416a5 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 1 Nov 2021 14:13:16 +0800 Subject: [PATCH 155/454] Update makedumpfile to 1.7.0 Signed-off-by: Coiby Xu --- ...e-Increase-SECTION_MAP_LAST_BIT-to-5.patch | 42 ------------- ...ss-proc-kcore-when-finding-max_paddr.patch | 60 ------------------- ...-proc-kcore-when-making-ELF-dumpfile.patch | 43 ------------- kexec-tools.spec | 9 +-- sources | 2 +- 5 files changed, 2 insertions(+), 154 deletions(-) delete mode 100644 kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch delete mode 100644 kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch delete mode 100644 kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch diff --git a/kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch b/kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch deleted file mode 100644 index a59bef1..0000000 --- a/kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch +++ /dev/null @@ -1,42 +0,0 @@ -From 646456862df8926ba10dd7330abf3bf0f887e1b6 Mon Sep 17 00:00:00 2001 -From: Kazuhito Hagio -Date: Wed, 26 May 2021 14:31:26 +0900 -Subject: [PATCH] Increase SECTION_MAP_LAST_BIT to 5 - -* Required for kernel 5.12 - -Kernel commit 1f90a3477df3 ("mm: teach pfn_to_online_page() about -ZONE_DEVICE section collisions") added a section flag -(SECTION_TAINT_ZONE_DEVICE) and causes makedumpfile an error on -some machines like this: - - __vtop4_x86_64: Can't get a valid pmd_pte. - readmem: Can't convert a virtual address(ffffe2bdc2000000) to physical address. - readmem: type_addr: 0, addr:ffffe2bdc2000000, size:32768 - __exclude_unnecessary_pages: Can't read the buffer of struct page. - create_2nd_bitmap: Can't exclude unnecessary pages. - -Increase SECTION_MAP_LAST_BIT to 5 to fix this. The bit had not -been used until the change, so we can just increase the value. - -Signed-off-by: Kazuhito Hagio ---- - makedumpfile.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/makedumpfile-1.6.9/makedumpfile.h b/makedumpfile-1.6.9/makedumpfile.h -index 93aa774..79046f2 100644 ---- a/makedumpfile-1.6.9/makedumpfile.h -+++ b/makedumpfile-1.6.9/makedumpfile.h -@@ -195,7 +195,7 @@ isAnon(unsigned long mapping) - * 2. it has been verified that (1UL<<2) was never set, so it is - * safe to mask that bit off even in old kernels. - */ --#define SECTION_MAP_LAST_BIT (1UL<<4) -+#define SECTION_MAP_LAST_BIT (1UL<<5) - #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) - #define NR_SECTION_ROOTS() divideup(num_section, SECTIONS_PER_ROOT()) - #define SECTION_NR_TO_PFN(sec) ((sec) << PFN_SECTION_SHIFT()) --- -2.29.2 - diff --git a/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch b/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch deleted file mode 100644 index f79ea55..0000000 --- a/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch +++ /dev/null @@ -1,60 +0,0 @@ -From 38d921a2ef50ebd36258097553626443ffe27496 Mon Sep 17 00:00:00 2001 -From: Coiby Xu -Date: Tue, 15 Jun 2021 18:26:31 +0800 -Subject: [PATCH] check for invalid physical address of /proc/kcore - when finding max_paddr - -Kernel commit 464920104bf7adac12722035bfefb3d772eb04d8 ("/proc/kcore: -update physical address for kcore ram and text") sets an invalid paddr -(0xffffffffffffffff = -1) for PT_LOAD segments of not direct mapped -regions: - - $ readelf -l /proc/kcore - ... - Program Headers: - Type Offset VirtAddr PhysAddr - FileSiz MemSiz Flags Align - NOTE 0x0000000000000120 0x0000000000000000 0x0000000000000000 - 0x0000000000002320 0x0000000000000000 0x0 - LOAD 0x1000000000010000 0xd000000000000000 0xffffffffffffffff - ^^^^^^^^^^^^^^^^^^ - 0x0001f80000000000 0x0001f80000000000 RWE 0x10000 - -makedumpfile uses max_paddr to calculate the number of sections for -sparse memory model thus wrong number is obtained based on max_paddr -(-1). This error could lead to the failure of copying /proc/kcore -for RHEL-8.5 on ppc64le machine [1]: - - $ makedumpfile /proc/kcore vmcore1 - get_mem_section: Could not validate mem_section. - get_mm_sparsemem: Can't get the address of mem_section. - - makedumpfile Failed. - -Let's check if the phys_start of the segment is a valid physical -address to fix this problem. - -[1] https://bugzilla.redhat.com/show_bug.cgi?id=1965267 - -Reported-by: Xiaoying Yan -Signed-off-by: Coiby Xu ---- - elf_info.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/makedumpfile-1.6.9/elf_info.c b/makedumpfile-1.6.9/elf_info.c -index e8affb7..bc24083 100644 ---- a/makedumpfile-1.6.9/elf_info.c -+++ b/makedumpfile-1.6.9/elf_info.c -@@ -628,7 +628,7 @@ get_max_paddr(void) - - for (i = 0; i < num_pt_loads; i++) { - pls = &pt_loads[i]; -- if (max_paddr < pls->phys_end) -+ if (pls->phys_start != NOT_PADDR && max_paddr < pls->phys_end) - max_paddr = pls->phys_end; - } - return max_paddr; --- -2.29.2 - diff --git a/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch b/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch deleted file mode 100644 index 8cf780c..0000000 --- a/kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 9a6f589d99dcef114c89fde992157f5467028c8f Mon Sep 17 00:00:00 2001 -From: Tao Liu -Date: Fri, 18 Jun 2021 18:28:04 +0800 -Subject: [PATCH] check for invalid physical address of /proc/kcore - when making ELF dumpfile - -Previously when executing makedumpfile with -E option against -/proc/kcore, makedumpfile will fail: - - # makedumpfile -E -d 31 /proc/kcore kcore.dump - ... - write_elf_load_segment: Can't convert physaddr(ffffffffffffffff) to an offset. - - makedumpfile Failed. - -It's because /proc/kcore contains PT_LOAD program headers which have -physaddr (0xffffffffffffffff). With -E option, makedumpfile will -try to convert the physaddr to an offset and fails. - -Skip the PT_LOAD program headers which have such physaddr. - -Signed-off-by: Tao Liu -Signed-off-by: Kazuhito Hagio ---- - makedumpfile.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/makedumpfile-1.6.9/makedumpfile.c b/makedumpfile-1.6.9/makedumpfile.c -index 894c88e..fcb571f 100644 ---- a/makedumpfile-1.6.9/makedumpfile.c -+++ b/makedumpfile-1.6.9/makedumpfile.c -@@ -7764,7 +7764,7 @@ write_elf_pages_cyclic(struct cache_data *cd_header, struct cache_data *cd_page) - if (!get_phdr_memory(i, &load)) - return FALSE; - -- if (load.p_type != PT_LOAD) -+ if (load.p_type != PT_LOAD || load.p_paddr == NOT_PADDR) - continue; - - off_memory= load.p_offset; --- -2.29.2 - diff --git a/kexec-tools.spec b/kexec-tools.spec index 5dbf625..1f25779 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,6 +1,6 @@ %global eppic_ver e8844d3793471163ae4a56d8f95897be9e5bd554 %global eppic_shortver %(c=%{eppic_ver}; echo ${c:0:7}) -%global mkdf_ver 1.6.9 +%global mkdf_ver 1.7.0 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools @@ -108,9 +108,6 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # -Patch601: ./kexec-tools-2.0.22-makedumpfile-Increase-SECTION_MAP_LAST_BIT-to-5.patch -Patch602: ./kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-finding-max_paddr.patch -Patch603: ./kexec-tools-2.0.22-makedumpfile-check-for-invalid-physical-address-proc-kcore-when-making-ELF-dumpfile.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -126,10 +123,6 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} -%patch601 -p1 -%patch602 -p1 -%patch603 -p1 - %ifarch ppc %define archdef ARCH=ppc %endif diff --git a/sources b/sources index 80b4d4e..2a1c797 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 SHA512 (kexec-tools-2.0.22.tar.xz) = 7580860f272eee5af52139809f12961e5a5d3a65f4e191183ca9c845410425d25818945ac14ed04a60e6ce474dc2656fc6a14041177b0bf703f450820c7d6aba -SHA512 (makedumpfile-1.6.9.tar.gz) = 9982985498ae641d390c3b87d92aecd263a502f1a4a9e96e145d86d8778b9e778e4ee98034ef4dbe12ed5586c57278917ea5f3c9ae2989ad1ac051215e03b3d9 +SHA512 (makedumpfile-1.7.0.tar.gz) = 579a1fb79d023a1419fc8612a02a04dda3e3b3d72455566433ab6bec08627aa9a176c55566393a081a7aae3fd0543800196596b25445b21b16346556723e9cf7 From 267a088b2a15af26d431bfb10ae85d4d7fd1f98b Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 8 Nov 2021 14:09:13 +0800 Subject: [PATCH 156/454] Release 2.0.23-1 Signed-off-by: Coiby Xu --- kexec-tools.spec | 11 +++++++++-- sources | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 1f25779..331d61d 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,8 +4,8 @@ %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools -Version: 2.0.22 -Release: 8%{?dist} +Version: 2.0.23 +Release: 1%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -375,6 +375,13 @@ done %endif %changelog +* Mon Nov 18 2021 Coiby - 2.0.23-1 +- Update kexec-tools to 2.0.23 +- Rebase makedumpfile to 1.7.0 +- fix broken extra_bins when installing multiple binaries +- mkdumprd: drop mountaddr/mountproto nfs mount options +- selftest: kill VM reliably by recursively kill children processes + * Thu Sep 16 2021 Kairui Song - 2.0.22-8 - 92-crashkernel.install: fix exit code - dracut-early-kdump.sh: make it POSIX compatible diff --git a/sources b/sources index 2a1c797..5069108 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 -SHA512 (kexec-tools-2.0.22.tar.xz) = 7580860f272eee5af52139809f12961e5a5d3a65f4e191183ca9c845410425d25818945ac14ed04a60e6ce474dc2656fc6a14041177b0bf703f450820c7d6aba +SHA512 (kexec-tools-2.0.23.tar.xz) = b6e3b967cacc31c434b185d25da4d53c822ae4bbcec26ef9d6cb171f294fdcc80913d381e686a0a41e025187835f4dc088052ff88efe75a021d7624c8b1a1ed8 SHA512 (makedumpfile-1.7.0.tar.gz) = 579a1fb79d023a1419fc8612a02a04dda3e3b3d72455566433ab6bec08627aa9a176c55566393a081a7aae3fd0543800196596b25445b21b16346556723e9cf7 From 9ffda5bc1c789d00737ebe9b554691d029ecf492 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Wed, 10 Nov 2021 16:56:53 +0800 Subject: [PATCH 157/454] Enable zstd compression for makedumpfile in kexec-tools.spec The Zstandard (zstd) compression method is not enabled: $ makedumpfile -v makedumpfile: version 1.7.0 (released on 8 Nov 2021) lzo enabled snappy enabled zstd disabled This patch will enable it when building kexec-tools rpm package. Signed-off-by: Tao Liu Acked-by: Coiby Xu --- kexec-tools.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 331d61d..8efc17a 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -71,7 +71,7 @@ Requires: dracut-squash >= 050 Requires: ethtool Recommends: grubby BuildRequires: make -BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel +BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel libzstd-devel BuildRequires: pkgconfig intltool gettext BuildRequires: systemd-rpm-macros BuildRequires: automake autoconf libtool @@ -151,7 +151,7 @@ cp %{SOURCE34} . make %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 make -C eppic-%{eppic_ver}/libeppic -make -C makedumpfile-%{mkdf_ver} LINKTYPE=dynamic USELZO=on USESNAPPY=on +make -C makedumpfile-%{mkdf_ver} LINKTYPE=dynamic USELZO=on USESNAPPY=on USEZSTD=on make -C makedumpfile-%{mkdf_ver} LDFLAGS="$LDFLAGS -I../eppic-%{eppic_ver}/libeppic -L../eppic-%{eppic_ver}/libeppic" eppic_makedumpfile.so %endif From 960a132c31facf574a6d48dc2d25771aaee56c5f Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Thu, 21 Oct 2021 10:17:01 +0800 Subject: [PATCH 158/454] sysconfig: make kexec_file_load as default option on aarch64 Signed-off-by: Pingfan Liu Acked-by: Coiby Xu --- kdump.sysconfig.aarch64 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump.sysconfig.aarch64 b/kdump.sysconfig.aarch64 index fedd3bc..67a2af7 100644 --- a/kdump.sysconfig.aarch64 +++ b/kdump.sysconfig.aarch64 @@ -28,7 +28,7 @@ KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory # # Example: # KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" +KEXEC_ARGS="-s" #Where to find the boot image #KDUMP_BOOTDIR="/boot" From c59dfe938e1620b6ad264da0c8a59ed7996418e1 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Thu, 21 Oct 2021 10:17:02 +0800 Subject: [PATCH 159/454] sysconfig: make kexec_file_load as default option on ppc64le Signed-off-by: Pingfan Liu Acked-by: Coiby Xu --- kdump.sysconfig.ppc64le | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump.sysconfig.ppc64le b/kdump.sysconfig.ppc64le index ebb22f6..270a2cf 100644 --- a/kdump.sysconfig.ppc64le +++ b/kdump.sysconfig.ppc64le @@ -28,7 +28,7 @@ KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_di # # Example: # KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="--dt-no-old-root" +KEXEC_ARGS="--dt-no-old-root -s" #Where to find the boot image #KDUMP_BOOTDIR="/boot" From 8cc51f3ab922cad5e857e37440d65466b1b8c2fd Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Mon, 15 Nov 2021 22:23:42 +0800 Subject: [PATCH 160/454] Document/kexec-kdump-howto.txt: improve notes for kdump_pre and kdump_post scripts Signed-off-by: Pingfan Liu Acked-by: Coiby Xu --- kdump.conf.5 | 14 ++++++++++---- kexec-kdump-howto.txt | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kdump.conf.5 b/kdump.conf.5 index 2c5a2bc..6e6cafa 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -118,8 +118,11 @@ All files under /etc/kdump/post.d are collectively sorted and executed in lexical order, before binary or script specified kdump_post parameter is executed. .PP -Note that scripts written for use with this directive must use -the /bin/bash interpreter. +Note that scripts written for use with this directive must use the /bin/bash +interpreter. And since these scripts run in kdump enviroment, the reference to +the storage or network device in the scripts should adhere to the section +'Supported dump target types and requirements' in kexec-kdump-howto.txt. + .RE .B kdump_pre @@ -139,8 +142,11 @@ kdump_pre parameter is executed. Even if the binary or script in /etc/kdump/pre.d directory returns non 0 exit status, the processing is continued. .PP -Note that scripts written for this directive must use -the /bin/bash interpreter. +Note that scripts written for use with this directive must use the /bin/bash +interpreter. And since these scripts run in kdump enviroment, the reference to +the storage or network device in the scripts should adhere to the section +'Supported dump target types and requirements' in kexec-kdump-howto.txt. + .RE .B extra_bins diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 88af607..1aeffc7 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -621,6 +621,9 @@ If /etc/kdump/post.d directory exist, All files in the directory are collectively sorted and executed in lexical order, before binary or script specified kdump_post parameter is executed. +In these scripts, the reference to the storage or network device should adhere +to the section 'Supported dump target types and requirements' + Kdump Pre-Capture Executable ---------------------------- @@ -634,6 +637,9 @@ kdump_pre parameter is executed. Even if the binary or script in /etc/kdump/pre.d directory returns non 0 exit status, the processing is continued. +In these scripts, the reference to the storage or network device should adhere +to the section 'Supported dump target types and requirements' + Extra Binaries -------------- From c3c8df3745a711992f1aa952e24eef0790924400 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 18 Nov 2021 12:26:01 +0800 Subject: [PATCH 161/454] add keytuils as a weak dependency for POWER When secureboot is enabled, kdumpctl needs to use keyctl to add/remove a key to/from the .ima keyring. Fixes: commit 596fa0a07f089a9dd54cf631124d88653b4d77ec ("kdumpctl: enable secure boot on ppc64le LPARs") Signed-off-by: Coiby Xu --- kexec-tools.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/kexec-tools.spec b/kexec-tools.spec index 8efc17a..dcab391 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -63,6 +63,7 @@ Source201: dracut-fadump-module-setup.sh %ifarch ppc64 ppc64le Requires(post): servicelog +Recommends: keyutils %endif Requires(pre): coreutils sed zlib Requires: dracut >= 050 From f0892eeceb96072822f74e7a9ad491f61867f343 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 1 Dec 2021 15:37:06 +0800 Subject: [PATCH 162/454] kdump/ppc64: suppress the error message "Could not find a registered notification tool" from servicelog_notify When kexec-tools is newly installed, kdump migration action hasn't registered and the following error could occur, INF dnf.rpm: Could not find a registered notification tool with the specified command ('/usr/lib/kdump/kdump-migrate-action.sh'). "servicelog_notify --list" could list registered notification tools for a command but it outputs the above error as well. So simply redirect the error to /dev/null when running "servicelog_notify --remove". Fixes: commit 146f66262222e96bca47b691ed243fa5097aa55c ("kdump/ppc64: migration action registration clean up") Acked-by: Tao Liu Acked-by: Hari Bathini Signed-off-by: Coiby Xu --- kexec-tools.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index dcab391..ab7f41f 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -265,7 +265,7 @@ mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{d touch /etc/kdump.conf %ifarch ppc64 ppc64le -servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh +servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh 2>/dev/null servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin %endif From 163c02970e4ddcf238b2ac09eadf380744e01ba2 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Mon, 20 Dec 2021 09:29:02 +0800 Subject: [PATCH 163/454] ppc64/ppc64le: drop cpu online rule in 40-redhat.rules in kdump initramfs Onlining secondary cpus breaks kdump completely on KVM on Power hosts Though we use maxcpus=1 by default but 40-redhat.rules will bring up all possible cpus by default. Thus before we get the kernel fix and the systemd rule fix let's remove the cpu rule in 40-redhat.rules for ppc64/ppc64le kdump initramfs. This is back ported from RHEL, and original credit goes to Dave Young Signed-off-by: Pingfan Liu Acked-by: Tao Liu --- dracut-module-setup.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 1ea0d95..c319fc2 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1010,11 +1010,29 @@ kdump_install_systemd_conf() { echo "ForwardToConsole=yes" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf" } +remove_cpu_online_rule() { + local file=${initdir}/usr/lib/udev/rules.d/40-redhat.rules + + sed -i '/SUBSYSTEM=="cpu"/d' "$file" +} + install() { + local arch + kdump_module_init kdump_install_conf remove_sysctl_conf + # Onlining secondary cpus breaks kdump completely on KVM on Power hosts + # Though we use maxcpus=1 by default but 40-redhat.rules will bring up all + # possible cpus by default. (rhbz1270174 rhbz1266322) + # Thus before we get the kernel fix and the systemd rule fix let's remove + # the cpu online rule in kdump initramfs. + arch=$(uname -m) + if [[ "$arch" = "ppc64le" ]] || [[ "$arch" = "ppc64" ]]; then + remove_cpu_online_rule + fi + if is_ssh_dump_target; then kdump_install_random_seed fi From 004daebefffcc81993413c4d4ce1f501294e3226 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 18 Dec 2021 16:14:44 +0800 Subject: [PATCH 164/454] dracut-early-kdump-module-setup.sh: install xargs and kdump-lib-initramfs.sh For earlykdump, kdump-lib-initramfs.sh is sourced by kdump-lib.sh, however it is not installed in dracut-early-kdump-module-setup.sh. Same as xargs, which is used by kdump-lib.sh. Otherwise earlykdump will report file not found errors. Fixes: a5faa052d4969cb66719d0b795d746449d3c71b7 ("kdump-lib-initramfs.sh: prepare to be a POSIX compatible lib") Fixes: 4f01cb1b0a4e1ea9467e9ace34d14dcb2fbe135a ("kdump-lib.sh: fix variable quoting issue") Signed-off-by: Tao Liu Acked-by: Coiby Xu --- dracut-early-kdump-module-setup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dracut-early-kdump-module-setup.sh b/dracut-early-kdump-module-setup.sh index 0e46823..0451118 100755 --- a/dracut-early-kdump-module-setup.sh +++ b/dracut-early-kdump-module-setup.sh @@ -50,7 +50,9 @@ install() { inst_binary "/usr/bin/gawk" "/usr/bin/awk" inst_binary "/usr/bin/logger" "/usr/bin/logger" inst_binary "/usr/bin/printf" "/usr/bin/printf" + inst_binary "/usr/bin/xargs" "/usr/bin/xargs" inst_script "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh" + inst_script "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump/kdump-lib-initramfs.sh" inst_script "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh" inst_hook cmdline 00 "$moddir/early-kdump.sh" inst_binary "$KDUMP_KERNEL" From 546c81a2050c4d65a95f1bbe563b76a19c13780f Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 28 Dec 2021 14:47:46 +0800 Subject: [PATCH 165/454] kdumpctl: remove some legacy code It seems the save_core function and vmcore detection was used a long time ago when kdump shares same userspace in first and second kernel. It's now heavily deprecated (only support cp, hardcoded path, dumpoops no longer exists) and not used. Now vmcore will never show up in first kernel for both kdump and fadump case, and kdumpctl is only used in first kernel, so just remove them. Signed-off-by: Kairui Song Acked-by: Coiby Xu --- kdumpctl | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/kdumpctl b/kdumpctl index 59ec068..ed2b963 100755 --- a/kdumpctl +++ b/kdumpctl @@ -72,32 +72,6 @@ determine_dump_mode() ddebug "DEFAULT_DUMP_MODE=$DEFAULT_DUMP_MODE" } -save_core() -{ - coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" - - mkdir -p "$coredir" - ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete" - if cp --sparse=always /proc/vmcore "$coredir/vmcore-incomplete"; then - mv "$coredir/vmcore-incomplete" "$coredir/vmcore" - dinfo "saved a vmcore to $coredir" - else - derror "failed to save a vmcore to $coredir" - fi - - # pass the dmesg to Abrt tool if exists, in order - # to collect the kernel oops message. - # https://fedorahosted.org/abrt/ - if [[ -x /usr/bin/dumpoops ]]; then - ddebug "makedumpfile --dump-dmesg $coredir/vmcore $coredir/dmesg" - makedumpfile --dump-dmesg "$coredir/vmcore" "$coredir/dmesg" > /dev/null 2>&1 - ddebug "dumpoops -d $coredir/dmesg" - if dumpoops -d "$coredir/dmesg" > /dev/null 2>&1; then - dinfo "kernel oops has been collected by abrt tool" - fi - fi -} - rebuild_fadump_initrd() { if ! $MKFADUMPRD "$DEFAULT_INITRD_BAK" "$TARGET_INITRD" --kver "$KDUMP_KERNELVER"; then @@ -1346,12 +1320,7 @@ main() case "$1" in start) - if [[ -s /proc/vmcore ]]; then - save_core - reboot - else - start - fi + start ;; stop) stop From 34d27c4c308d9eddc35ff2c81bfe3b1cef5749a5 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 16 Nov 2021 09:12:49 +0800 Subject: [PATCH 166/454] update default crashkernel value It has been decided to increase default crashkernel value to reduce the possibility of OOM. Fixes: 7b7ddab ("kdump-lib.sh: kdump_get_arch_recommend_size uses crashkernel.default") Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdump-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 2e2775c..b8f6c96 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -841,7 +841,7 @@ kdump_get_arch_recommend_size() else arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]') if [[ $arch == "X86_64" ]] || [[ $arch == "S390X" ]]; then - ck_cmdline="1G-4G:160M,4G-64G:192M,64G-1T:256M,1T-:512M" + ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M" elif [[ $arch == "AARCH64" ]]; then ck_cmdline="2G-:448M" elif [[ $arch == "PPC64LE" ]]; then From 105c01691ac200e7ce71795b2f41b64dd6cf3b58 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 16 Nov 2021 11:26:31 +0800 Subject: [PATCH 167/454] factor out kdump_get_arch_recommend_crashkernel Factor out kdump_get_arch_recommend_crashkernel to prepare for kdump-anaconda-plugin for example to retrieve the default crashkernel value. Note the support of crashkenrel.default is dropped. Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdump-lib.sh | 60 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index b8f6c96..b28db44 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -822,40 +822,52 @@ get_recommend_size() IFS="$OLDIFS" } +# get default crashkernel +# $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable +kdump_get_arch_recommend_crashkernel() +{ + local _arch _ck_cmdline _dump_mode + + if [[ -z "$1" ]]; then + if is_fadump_capable; then + _dump_mode=fadump + else + _dump_mode=kdump + fi + else + _dump_mode=$1 + fi + + _arch=$(uname -m) + + if [[ $_arch == "x86_64" ]] || [[ $_arch == "s390x" ]]; then + _ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M" + elif [[ $_arch == "aarch64" ]]; then + _ck_cmdline="2G-:448M" + elif [[ $_arch == "ppc64le" ]]; then + if [[ $_dump_mode == "fadump" ]]; then + _ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" + else + _ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" + fi + fi + + _ck_cmdline=${_ck_cmdline//-:/-102400T:} + echo -n "$_ck_cmdline" +} + # return recommended size based on current system RAM size # $1: kernel version, if not set, will defaults to $(uname -r) kdump_get_arch_recommend_size() { - local kernel=$1 arch + local _ck_cmdline if ! [[ -r "/proc/iomem" ]]; then echo "Error, can not access /proc/iomem." return 1 fi - - [[ -z $kernel ]] && kernel=$(uname -r) - ck_cmdline=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2> /dev/null) - - if [[ -n $ck_cmdline ]]; then - ck_cmdline=${ck_cmdline#crashkernel=} - else - arch=$(lscpu | grep Architecture | awk -F ":" '{ print $2 }' | tr '[:lower:]' '[:upper:]') - if [[ $arch == "X86_64" ]] || [[ $arch == "S390X" ]]; then - ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M" - elif [[ $arch == "AARCH64" ]]; then - ck_cmdline="2G-:448M" - elif [[ $arch == "PPC64LE" ]]; then - if is_fadump_capable; then - ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" - else - ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" - fi - fi - fi - - ck_cmdline=${ck_cmdline//-:/-102400T:} sys_mem=$(get_system_size) - + _ck_cmdline=$(kdump_get_arch_recommend_crashkernel) get_recommend_size "$sys_mem" "$ck_cmdline" } From 796d0f6fd2932fd7c009f4517133b1a9c39501e5 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 16 Nov 2021 12:23:02 +0800 Subject: [PATCH 168/454] provide kdumpctl get-default-crashkernel for kdump_anaconda_addon and RPM scriptlet Provide "kdumpctl get-default-crashkernel" for kdump_anaconda_addon so crashkernel.default isn't needed. When fadump is on, kdump_anaconda_addon would need to specify the dump mode, i.e. "kdumpctl get-default-crashkernel fadump". This interface would also be used by RPM scriptlet [1] to fetch default crashkernel value. [1] https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/ Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kdumpctl b/kdumpctl index ed2b963..48aca00 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1273,6 +1273,13 @@ do_estimate() fi } +get_default_crashkernel() +{ + local _dump_mode=$1 + + kdump_get_arch_recommend_crashkernel "$_dump_mode" +} + reset_crashkernel() { local kernel=$1 entry crashkernel_default @@ -1361,6 +1368,9 @@ main() estimate) do_estimate ;; + get-default-crashkernel) + get_default_crashkernel "$2" + ;; reset-crashkernel) reset_crashkernel "$2" ;; From fb9e6838abef1e3a2ba43966f58a1f146989b148 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 16 Nov 2021 06:48:40 +0800 Subject: [PATCH 169/454] add a helper function to read kernel cmdline parameter from grubby --info This helper function will be used to retrieve the value of kernel cmdline parameters including crashkernel, fadump, swiotlb and etc. Suggested-by: Philipp Rudo Reviewed-by: Pingfan Liu Signed-off-by: Coiby Xu --- kdumpctl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kdumpctl b/kdumpctl index 48aca00..6f6bdd2 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1280,6 +1280,17 @@ get_default_crashkernel() kdump_get_arch_recommend_crashkernel "$_dump_mode" } +# Read kernel cmdline parameter for a specific kernel +# $1: kernel path, DEFAULT or kernel path, ALL not accepted +# $2: kernel cmldine parameter +get_grub_kernel_boot_parameter() +{ + local _kernel_path=$1 _para=$2 + + [[ $_kernel_path == ALL ]] && derror "kernel_path=ALL invalid for get_grub_kernel_boot_parameter" && return 1 + grubby --info="$_kernel_path" | sed -En -e "/^args=.*$/{s/^.*(\s|\")${_para}=(\S*).*\"$/\2/p;q}" +} + reset_crashkernel() { local kernel=$1 entry crashkernel_default From 3d2079c31cd80741ea6d44eb7f13d7f08be74a94 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 1 Dec 2021 16:57:15 +0800 Subject: [PATCH 170/454] add helper functions to get dump mode Add a helper function to get dump mode. The dump mode would be - fadump if fadump=on or fadump=nocma - kdump if fadump=off or empty fadump Otherwise return 1. Also add another helper function to return a kernel's dump mode. Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/kdumpctl b/kdumpctl index 6f6bdd2..a72b71b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1291,6 +1291,40 @@ get_grub_kernel_boot_parameter() grubby --info="$_kernel_path" | sed -En -e "/^args=.*$/{s/^.*(\s|\")${_para}=(\S*).*\"$/\2/p;q}" } +# get dump mode by fadump value +# return +# - fadump, if fadump=on or fadump=nocma +# - kdump, if fadump=off or empty fadump, return kdump +# - error if otherwise +get_dump_mode_by_fadump_val() +{ + local _fadump_val=$1 + + if [[ -z $_fadump_val ]] || [[ $_fadump_val == off ]]; then + echo -n kdump + elif [[ $_fadump_val == on ]] || [[ $_fadump_val == nocma ]]; then + echo -n fadump + else + derror "invalid fadump=$_fadump_val" + return 1 + fi +} + +# get dump mode of a specific kernel +# based on its fadump kernel cmdline parameter +get_dump_mode_by_kernel() +{ + local _kernel_path=$1 _fadump_val _dump_mode + + _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel_path" fadump) + if _dump_mode=$(get_dump_mode_by_fadump_val "$_fadump_val"); then + echo -n "$_dump_mode" + else + derror "failed to get dump mode for kernel $_kernel_path" + exit + fi +} + reset_crashkernel() { local kernel=$1 entry crashkernel_default From 945cbbd59b34739c4a6b2f228c33f76e2981a18a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 7 Dec 2021 15:16:07 +0800 Subject: [PATCH 171/454] add helper functions to get kernel path by kernel release and the path of current running kernel grubby --info=kernel-path or --add-kernel=kernel-path accepts a kernel path (e.g. /boot/vmlinuz-5.14.14-200.fc34.x86_64) instead of kernel release (e.g 5.14.14-200.fc34.x86_64). So we need to know the kernel path given a kernel release. Although for Fedora/RHEL, the kernel path is "/boot/vmlinuz-", a path kernel could also be /boot///vmlinuz. So the most reliable way to find the kernel path given a kernel release is to use "grubby --info". For osbuild, a kernel path may not yet exist but it's valid for "grubby --update-kernel=KERNEL_PATH". For example, "grubby -info" may output something as follows, index=0 kernel="/var/cache/osbuild-worker/osbuild-store/tmp/tmp2prywdy5object/tree/boot/vmlinuz-5.15.10-100.fc34.x86_64" args="ro no_timer_check net.ifnames=0 console=tty1 console=ttyS0,115200n8" root="UUID=76a22bf4-f153-4541-b6c7-0332c0dfaeac" initrd="/var/cache/osbuild-worker/osbuild-store/tmp/tmp2prywdy5object/tree/boot/initramfs-5.15.10-100.fc34.x86_64.img" There is no need to check if path like /var/cache/osbuild-worker/osbuild-store/tmp/tmp2prywdy5object/tree/boot/vmlinuz-5.15.10-100.fc34.x86_64 physically exists. Note these helper functions doesn't support CoreOS/Atomic/Silverblue since grubby isn't used by them. Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kdumpctl b/kdumpctl index a72b71b..2ace803 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1325,6 +1325,36 @@ get_dump_mode_by_kernel() fi } +_filter_grubby_kernel_str() +{ + local _grubby_kernel_str=$1 + echo -n "$_grubby_kernel_str" | sed -n -e 's/^kernel="\(.*\)"/\1/p' +} + +_find_kernel_path_by_release() +{ + local _release="$1" _grubby_kernel_str _kernel_path + _grubby_kernel_str=$(grubby --info ALL | grep "^kernel=.*$_release") + _kernel_path=$(_filter_grubby_kernel_str "$_grubby_kernel_str") + if [[ -z $_kernel_path ]]; then + derror "kernel $_release doesn't exist" + return 1 + fi + echo -n "$_kernel_path" +} + +_get_current_running_kernel_path() +{ + local _release _path + + _release=$(uname -r) + if _path=$(_find_kernel_path_by_release "$_release"); then + echo -n "$_path" + else + return 1 + fi +} + reset_crashkernel() { local kernel=$1 entry crashkernel_default From 12ecbce359adb621da3e65fed689632a39599ce6 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 13 Dec 2021 10:57:13 +0800 Subject: [PATCH 172/454] fix incorrect usage of rpm-ostree to update kernel command line parameters CoreOS/Atomic/Silverblue use "rpm-ostree kargs" to manage kernel command line parameters. Fixes: 86130ec ("kdumpctl: Add kdumpctl reset-crashkernel") Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 2ace803..dd87693 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1370,9 +1370,9 @@ reset_crashkernel() if is_atomic; then if rpm-ostree kargs | grep -q "crashkernel="; then - rpm-ostree --replace="crashkernel=$crashkernel_default" + rpm-ostree kargs --replace="crashkernel=$crashkernel_default" else - rpm-ostree --append="crashkernel=$crashkernel_default" + rpm-ostree kargs --append="crashkernel=$crashkernel_default" fi else entry=$(grubby --info ALL | grep "^kernel=.*$kernel") From 140da74a340f872b2579fc75b50a36fe7015c0ba Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 1 Dec 2021 13:39:40 +0800 Subject: [PATCH 173/454] rewrite reset_crashkernel to support fadump and to used by RPM scriptlet Rewrite kdumpctl reset-crashkernel KERNEL_PATH as kdumpctl reset-crashkernel [--fadump=[on|off|nocma]] [--kernel=path_to_kernel] [--reboot] This interface would reset a specific kernel to the default crashkernel value given the kernel path. And it also supports grubby's syntax so there are the following special cases, - if --kernel not specified, - use KDUMP_KERNELVER if it's defined in /etc/sysconfig/kdump - otherwise use current running kernel, i.e. `uname -r` - if --kernel=DEFAULT, the default boot kernel is chosen - if --kernel=ALL, all kernels would have its crashkernel reset to the default value and the /etc/default/grub is updated as well --fadump=[on|off|nocma] toggles fadump on/off for the kernel provided in KERNEL_PATH. If --fadump is omitted, the dump mode is determined by parsing the kernel command line for the kernel(s) to update. CoreOS/Atomic/Silverblue needs to be treated as a special case because, - "rpm-ostree kargs" is used to manage kernel command line parameters so --kernel doesn't make sense and there is no need to find current running kernel - "rpm-ostree kargs" itself would prompt the user to reboot the system after modify the kernel command line parameter - POWER is not supported so we can assume the dump mode is always kdump This interface will also be called by kexec-tools RPM scriptlets [1] to reset crashkernel. Note the support of crashkenrel.default is dropped. [1] https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/ Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 203 +++++++++++++++++++++++++++++++++++++++++++++++------ kdumpctl.8 | 19 +++-- 2 files changed, 192 insertions(+), 30 deletions(-) diff --git a/kdumpctl b/kdumpctl index dd87693..1518e5c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1355,38 +1355,194 @@ _get_current_running_kernel_path() fi } -reset_crashkernel() +_update_grub() { - local kernel=$1 entry crashkernel_default - local grub_etc_default="/etc/default/grub" - - [[ -z $kernel ]] && kernel=$(uname -r) - crashkernel_default=$(cat "/usr/lib/modules/$kernel/crashkernel.default" 2> /dev/null) - - if [[ -z $crashkernel_default ]]; then - derror "$kernel doesn't have a crashkernel.default" - exit 1 - fi + local _kernel_path=$1 _crashkernel=$2 _dump_mode=$3 _fadump_val=$4 if is_atomic; then if rpm-ostree kargs | grep -q "crashkernel="; then - rpm-ostree kargs --replace="crashkernel=$crashkernel_default" + rpm-ostree kargs --replace="crashkernel=$_crashkernel" else - rpm-ostree kargs --append="crashkernel=$crashkernel_default" + rpm-ostree kargs --append="crashkernel=$_crashkernel" fi else - entry=$(grubby --info ALL | grep "^kernel=.*$kernel") - entry=${entry#kernel=} - entry=${entry#\"} - entry=${entry%\"} + [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" + grubby --args "crashkernel=$_crashkernel" --update-kernel "$_kernel_path" $zipl_arg + if [[ $_dump_mode == kdump ]]; then + grubby --remove-args="fadump" --update-kernel "$_kernel_path" + else + grubby --args="fadump=$_fadump_val" --update-kernel "$_kernel_path" + fi + fi + [[ $zipl_arg ]] && zipl > /dev/null +} - if [[ -f $grub_etc_default ]]; then - sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$crashkernel_default\2/" "$grub_etc_default" +_valid_grubby_kernel_path() +{ + [[ -n "$1" ]] && grubby --info="$1" > /dev/null 2>&1 +} + +_get_all_kernels_from_grubby() +{ + local _kernels _line _kernel_path _grubby_kernel_path=$1 + + for _line in $(grubby --info "$_grubby_kernel_path" | grep "^kernel="); do + _kernel_path=$(_filter_grubby_kernel_str "$_line") + _kernels="$_kernels $_kernel_path" + done + echo -n "$_kernels" +} + +GRUB_ETC_DEFAULT="/etc/default/grub" +# modify the kernel command line parameter in default grub conf +# +# $1: the name of the kernel command line parameter +# $2: new value. If empty, the parameter would be removed +_update_kernel_cmdline_in_grub_etc_default() +{ + local _para=$1 _val=$2 _para_val _regex + + if [[ -n $_val ]]; then + _para_val="$_para=$_val" + fi + + _regex='^(GRUB_CMDLINE_LINUX=.*)([[:space:]"])'"$_para"'=[^[:space:]"]*(.*)$' + if grep -q -E "$_regex" "$GRUB_ETC_DEFAULT"; then + sed -i -E 's/'"$_regex"'/\1\2'"$_para_val"'\3/' "$GRUB_ETC_DEFAULT" + elif [[ -n $_para_val ]]; then + # If the kernel parameter doesn't exist, put it in the first + sed -i -E 's/^(GRUB_CMDLINE_LINUX=")/\1'"$_para_val"' /' "$GRUB_ETC_DEFAULT" + fi +} + +reset_crashkernel() +{ + local _opt _val _dump_mode _fadump_val _reboot _grubby_kernel_path _kernel _kernels + local _old_crashkernel _new_crashkernel _new_dump_mode _crashkernel_changed + local _new_fadump_val _old_fadump_val _what_is_updated + + for _opt in "$@"; do + case "$_opt" in + --fadump=*) + _val=${_opt#*=} + if _dump_mode=$(get_dump_mode_by_fadump_val $_val); then + _fadump_val=$_val + else + derror "failed to determine dump mode" + exit + fi + ;; + --kernel=*) + _val=${_opt#*=} + if ! _valid_grubby_kernel_path $_val; then + derror "Invalid $_opt, please specify a valid kernel path, ALL or DEFAULT" + exit + fi + _grubby_kernel_path=$_val + ;; + --reboot) + _reboot=yes + ;; + *) + derror "$_opt not recognized" + exit 1 + ;; + esac + done + + # 1. CoreOS uses "rpm-ostree kargs" instead of grubby to manage kernel command + # line. --kernel=ALL doesn't make sense for CoreOS. + # 2. CoreOS doesn't support POWER so the dump mode is always kdump. + # 3. "rpm-ostree kargs" would prompt the user to reboot the system after + # modifying the kernel command line so there is no need for kexec-tools + # to repeat it. + if is_atomic; then + _old_crashkernel=$(rpm-ostree kargs | sed -n -E 's/.*(^|\s)crashkernel=(\S*).*/\2/p') + _new_dump_mode=kdump + _new_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") + if [[ $_old_crashkernel != "$_new_crashkernel" ]]; then + _update_grub "" "$_new_crashkernel" "$_new_dump_mode" "" + if [[ $_reboot == yes ]]; then + systemctl reboot + fi + fi + return + fi + + # For non-ppc64le systems, the dump mode is always kdump since only ppc64le + # has FADump. + if [[ -z $_dump_mode && $(uname -m) != ppc64le ]]; then + _dump_mode=kdump + _fadump_val=off + fi + + # If the dump mode is determined, we can also know the default crashkernel value + if [[ -n $_dump_mode ]]; then + _crashkernel=$(kdump_get_arch_recommend_crashkernel "$_dump_mode") + fi + + # If --kernel-path=ALL, update GRUB_CMDLINE_LINUX in /etc/default/grub. + # + # An exception case is when the ppc64le user doesn't specify the fadump value. + # In this case, the dump mode would be determined by parsing the kernel + # command line of the kernel(s) to be updated thus don't update GRUB_CMDLINE_LINUX. + # + # The following code has been simplified because of what has been done early, + # - set the dump mode as kdump for non-ppc64le cases + # - retrieved the default crashkernel value for given dump mode + if [[ $_grubby_kernel_path == ALL && -n $_dump_mode ]]; then + _update_kernel_cmdline_in_grub_etc_default crashkernel "$_crashkernel" + # remove the fadump if fadump is disabled + [[ $_fadump_val == off ]] && _fadump_val="" + _update_kernel_cmdline_in_grub_etc_default fadump "$_fadump_val" + fi + + # If kernel-path not specified, either + # - use KDUMP_KERNELVER if it's defined + # - use current running kernel + if [[ -z $_grubby_kernel_path ]]; then + if [[ -z $KDUMP_KERNELVER ]] || + ! _kernel_path=$(_find_kernel_path_by_release "$KDUMP_KERNELVER"); then + if ! _kernel_path=$(_get_current_running_kernel_path); then + derror "no running kernel found" + exit 1 + fi + fi + _kernels=$_kernel_path + else + _kernels=$(_get_all_kernels_from_grubby "$_grubby_kernel_path") + fi + + for _kernel in $_kernels; do + if [[ -z $_dump_mode ]]; then + _new_dump_mode=$(get_dump_mode_by_kernel "$_kernel") + _new_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") + _new_fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + else + _new_dump_mode=$_dump_mode + _new_crashkernel=$_crashkernel + _new_fadump_val=$_fadump_val fi - [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" - grubby --args "$crashkernel_default" --update-kernel "$entry" $zipl_arg - [[ $zipl_arg ]] && zipl > /dev/null + _old_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) + _old_fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + if [[ $_old_crashkernel != "$_new_crashkernel" || $_old_fadump_val != "$_new_fadump_val" ]]; then + _update_grub "$_kernel" "$_new_crashkernel" "$_new_dump_mode" "$_new_fadump_val" + if [[ $_reboot != yes ]]; then + if [[ $_old_crashkernel != "$_new_crashkernel" ]]; then + _what_is_updated="Updated crashkernel=$_new_crashkernel" + else + # This case happens only when switching between fadump=on and fadump=nocma + _what_is_updated="Updated fadump=$_new_fadump_val" + fi + dwarn "$_what_is_updated for kernel=$_kernel. Please reboot the system for the change to take effect." + fi + _crashkernel_changed=yes + fi + done + + if [[ $_reboot == yes && $_crashkernel_changed == yes ]]; then + reboot fi } @@ -1447,7 +1603,8 @@ main() get_default_crashkernel "$2" ;; reset-crashkernel) - reset_crashkernel "$2" + shift + reset_crashkernel "$@" ;; *) dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}" diff --git a/kdumpctl.8 b/kdumpctl.8 index 74be062..067117b 100644 --- a/kdumpctl.8 +++ b/kdumpctl.8 @@ -50,14 +50,19 @@ Estimate a suitable crashkernel value for current machine. This is a best-effort estimate. It will print a recommanded crashkernel value based on current kdump setup, and list some details of memory usage. .TP -.I reset-crashkernel [KERNEL] -Reset crashkernel value to default value. kdumpctl will try to read -from /usr/lib/modules//crashkernel.default and reset specified -kernel's crashkernel cmdline value. If no kernel is -specified, will reset current running kernel's crashkernel value. -If /usr/lib/modules//crashkernel.default doesn't exist, will -simply exit return 1. +.I reset-crashkernel [--kernel=path_to_kernel] [--reboot] +Reset crashkernel to default value recommended by kexec-tools. If no kernel +is specified, will reset KDUMP_KERNELVER if it's defined in /etc/sysconfig/kdump +or current running kernel's crashkernel value if KDUMP_KERNELVER is empty. You can +also specify --kernel=ALL and --kernel=DEFAULT which have the same meaning as +grubby's kernel-path=ALL and kernel-path=DEFAULT. ppc64le supports FADump and +supports an additonal [--fadump=[on|off|nocma]] parameter to toggle FADump +on/off. +Note: The memory requirements for kdump varies heavily depending on the +used hardware and system configuration. Thus the recommended +crashkernel might not work for your specific setup. Please test if +kdump works after resetting the crashkernel value. .SH "SEE ALSO" .BR kdump.conf (5), From 73ced7f451a725f4a2f7db5f0e1c6e7918538204 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 15 Nov 2021 15:45:59 +0800 Subject: [PATCH 174/454] introduce the auto_reset_crashkernel option to kdump.conf This option will determine whether to reset kernel crashkernel to new default value or not when kexec-tools updates the default crashkernel value and existing kernels using the old default kernel crashkernel value. Default to yes. Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdump.conf | 7 +++++++ kdump.conf.5 | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/kdump.conf b/kdump.conf index dea2e94..d4fc78b 100644 --- a/kdump.conf +++ b/kdump.conf @@ -11,6 +11,12 @@ # # Supported options: # +# auto_reset_crashkernel +# - whether to reset kernel crashkernel to new default value +# or not when kexec-tools updates the default crashkernel value and +# existing kernels using the old default kernel crashkernel value. +# The default value is yes. +# # raw # - Will dd /proc/vmcore into . # Use persistent device names for partition devices, @@ -170,6 +176,7 @@ #ssh user@my.server.com #ssh user@2001:db8::1:2:3:4 #sshkey /root/.ssh/kdump_id_rsa +auto_reset_crashkernel yes path /var/crash core_collector makedumpfile -l --message-level 7 -d 31 #core_collector scp diff --git a/kdump.conf.5 b/kdump.conf.5 index 6e6cafa..e3e9900 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -26,6 +26,12 @@ understand how this configuration file affects the behavior of kdump. .SH OPTIONS +.B auto_reset_crashkernel +.RS +determine whether to reset kernel crashkernel to new default value +or not when kexec-tools updates the default crashkernel value and +existing kernels using the old default kernel crashkernel value + .B raw .RS Will dd /proc/vmcore into . Use persistent device names for From 0adb0f4a8c4c69ba54171f0113a4fbfc1729900f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 1 Dec 2021 15:33:13 +0800 Subject: [PATCH 175/454] try to reset kernel crashkernel when kexec-tools updates the default crashkernel value kexec-tools could update the default crashkernel value. When auto_reset_crashkernel=yes, reset kernel to new crashkernel value in the following two cases, - crashkernel=auto is found in the kernel cmdline - the kernel crashkernel was previously set by kexec-tools i.e. the kernel is using old default crashkernel value To tell if the user is using a custom value for the kernel crashkernel or not, we assume the user would never use the default crashkernel value as custom value. When kexec-tools gets updated, 1. save the default crashkernel value of the older package to /tmp/crashkernel (for POWER system, /tmp/crashkernel_fadump is saved as well). 2. If auto_reset_crashkernel=yes, iterate all installed kernels. For each kernel, compare its crashkernel value with the old default crashkernel and reset it if yes The implementation makes use of two RPM scriptlets [2], - %pre is run before a package is installed so we can use it to save old default crashkernel value - %post is run after a package installed so we can use it to try to reset kernel crashkernel There are several problems when running kdumpctl in the RPM scripts for CoreOS/Atomic/Silverblue, for example, the lock can't be acquired by kdumpctl, "rpm-ostree kargs" can't be run and etc.. So don't enable this feature for CoreOS/Atomic/Silverblue. Note latest shellcheck (0.8.0) gives false positives about the associative array as of this commit. And Fedora's shellcheck is 0.7.2 and can't even correctly parse the shell code because of the associative array. [1] https://github.com/koalaman/shellcheck/issues/2399 [2] https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/ Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 35 +++++++++++++++++++++++++++++++++++ kexec-tools.spec | 22 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/kdumpctl b/kdumpctl index 1518e5c..07e6f8b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1546,6 +1546,36 @@ reset_crashkernel() fi } +# shellcheck disable=SC2154 # false positive when dereferencing an array +reset_crashkernel_after_update() +{ + local _kernel _crashkernel _dump_mode _fadump_val _old_default_crashkernel _new_default_crashkernel + declare -A _crashkernel_vals + + _crashkernel_vals[old_kdump]=$(cat /tmp/old_default_crashkernel 2> /dev/null) + _crashkernel_vals[old_fadump]=$(cat /tmp/old_default_crashkernel_fadump 2> /dev/null) + _crashkernel_vals[new_kdump]=$(get_default_crashkernel kdump) + _crashkernel_vals[new_fadump]=$(get_default_crashkernel fadump) + + for _kernel in $(_get_all_kernels_from_grubby); do + _crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) + if [[ $_crashkernel == auto ]]; then + reset_crashkernel "--kernel=$_kernel" + elif [[ -n $_crashkernel ]]; then + _dump_mode=$(get_dump_mode_by_kernel "$_kernel") + _old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]} + _new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]} + if [[ $_crashkernel == "$_old_default_crashkernel" ]] && + [[ $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then + _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + if _update_grub "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then + echo "For kernel=$_kernel, crashkernel=$_new_default_crashkernel now." + fi + fi + fi + done +} + if [[ ! -f $KDUMP_CONFIG_FILE ]]; then derror "Error: No kdump config file found!" exit 1 @@ -1606,6 +1636,11 @@ main() shift reset_crashkernel "$@" ;; + reset-crashkernel-after-update) + if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then + reset_crashkernel_after_update + fi + ;; *) dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}" exit 1 diff --git a/kexec-tools.spec b/kexec-tools.spec index ab7f41f..b2a0e20 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -258,6 +258,15 @@ chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpini mkdir -p $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ +%pre +# save the old default crashkernel values to /tmp/ when upgrading the package +if ! grep -q "ostree" /proc/cmdline && [ $1 == 2 ] && grep -q get-default-crashkernel /usr/bin/kdumpctl; then + kdumpctl get-default-crashkernel kdump > /tmp/old_default_crashkernel 2>/dev/null +%ifarch ppc64 ppc64le + kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null +%endif +fi + %post # Initial installation %systemd_post kdump.service @@ -291,6 +300,19 @@ then mv /etc/sysconfig/kdump.new /etc/sysconfig/kdump fi +# try to reset kernel crashkernel value to new default value when upgrading +# the package +if ! grep -q "ostree" /proc/cmdline && [ $1 == 2 ]; then + kdumpctl reset-crashkernel-after-update + rm /tmp/old_default_crashkernel 2>/dev/null +%ifarch ppc64 ppc64le + rm /tmp/old_default_crashkernel_fadump 2>/dev/null +%endif + # dnf would complain about the exit code not being 0. To keep it happy, + # always return 0 + : +fi + %postun %systemd_postun_with_restart kdump.service From 5e8c751c39a5ec9d10009cba1c2bd554a5763b90 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 2 Dec 2021 17:19:50 +0800 Subject: [PATCH 176/454] reset kernel crashkernel for the special case where the kernel is updated right after kexec-tools When kexec-tools updates the default crashkernel value, it will try to reset the existing installed kernels including the currently running kernel. So the running kernel could have different kernel cmdline parameters from /proc/cmdline. When installing a kernel after updating kexec-tools, /usr/lib/kernel/install.d/20-grub.install would be called by kernel-install [1] which would use /proc/cmdline to set up new kernel's cmdline. To address this special case, reset the new kernel's crashkernel and fadump value to the value that would be used by running kernel after rebooting by the installation hook. One side effect of this commit is it would reset the installed kernel's crashkernel even currently running kernel don't use the default crashkernel value after rebooting. But I think this side effect is a benefit for the user. The implementation depends on kernel-install which run the scripts in /usr/lib/kernel/install.d passing the following arguments, add KERNEL-VERSION $BOOT/MACHINE-ID/KERNEL-VERSION/ KERNEL-IMAGE [INITRD-FILE ...] An concrete example is given as follows, add 5.11.12-300.fc34.x86_64 /boot/e986846f63134c7295458cf36300ba5b/5.11.12-300.fc34.x86_64 /lib/modules/5.11.12-300.fc34.x86_64/vmlinuz kernel-install could be started by the kernel package's RPM scriplet [2]. As mentioned in previous commit "try to reset kernel crashkernel when kexec-tools updates the default crashkernel value", kdumpctl has difficulty running in RPM scriptlet fore CoreOS. But rpm-ostree ignores all kernel hooks, there is no need to disable the kernel hook for CoreOS/Atomic/Silverblue. But a collaboration between rpm-ostree and kexec-tools is needed [3] to take care of this special case. Note the crashkernel.default support is dropped. [1] https://www.freedesktop.org/software/systemd/man/kernel-install.html [2] https://src.fedoraproject.org/rpms/kernel/blob/rawhide/f/kernel.spec#_2680 [3] https://github.com/coreos/rpm-ostree/issues/2894 Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- 92-crashkernel.install | 135 +---------------------------------------- kdumpctl | 31 ++++++++++ 2 files changed, 32 insertions(+), 134 deletions(-) diff --git a/92-crashkernel.install b/92-crashkernel.install index 78365ff..1d67a13 100755 --- a/92-crashkernel.install +++ b/92-crashkernel.install @@ -5,142 +5,9 @@ KERNEL_VERSION="$2" KDUMP_INITRD_DIR_ABS="$3" KERNEL_IMAGE="$4" -grub_etc_default="/etc/default/grub" - -ver_lt() { - [[ "$(echo -e "$1\n$2" | sort -V)" == $1$'\n'* ]] && [[ $1 != "$2" ]] -} - -# Read crashkernel= value in /etc/default/grub -get_grub_etc_ck() { - [[ -e $grub_etc_default ]] && \ - sed -n -e "s/^GRUB_CMDLINE_LINUX=.*\(crashkernel=[^\ \"]*\)[\ \"].*$/\1/p" $grub_etc_default -} - -# Read crashkernel.default value of specified kernel -get_ck_default() { - ck_file="/usr/lib/modules/$1/crashkernel.default" - [[ -f "$ck_file" ]] && cat "$ck_file" -} - -# Iterate installed kernels, find the kernel with the highest version that has a -# valid crashkernel.default file, exclude current installing/removing kernel -# -# $1: a string representing a crashkernel= cmdline. If given, will also check the -# content of crashkernel.default, only crashkernel.default with the same value will match -get_highest_ck_default_kver() { - for kernel in $(find /usr/lib/modules -maxdepth 1 -mindepth 1 -printf "%f\n" | sort --version-sort -r); do - [[ $kernel == "$KERNEL_VERSION" ]] && continue - [[ -s "/usr/lib/modules/$kernel/crashkernel.default" ]] || continue - - echo "$kernel" - return 0 - done - - return 1 -} - -set_grub_ck() { - sed -i -e "s/^\(GRUB_CMDLINE_LINUX=.*\)crashkernel=[^\ \"]*\([\ \"].*\)$/\1$1\2/" "$grub_etc_default" -} - -# Set specified kernel's crashkernel cmdline value -set_kernel_ck() { - kernel=$1 - ck_cmdline=$2 - - entry=$(grubby --info ALL | grep "^kernel=.*$kernel") - entry=${entry#kernel=} - entry=${entry#\"} - entry=${entry%\"} - - if [[ -z "$entry" ]]; then - echo "$0: failed to find boot entry for kernel $kernel" - return 1 - fi - - [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" - grubby --args "$ck_cmdline" --update-kernel "$entry" $zipl_arg - [[ $zipl_arg ]] && zipl > /dev/null ||: -} - case "$COMMAND" in add) - # - If current boot kernel is using default crashkernel value, update - # installing kernel's crashkernel value to its default value, - # - If intalling a higher version kernel, and /etc/default/grub's - # crashkernel value is using default value, update it to installing - # kernel's default value. - inst_ck_default=$(get_ck_default "$KERNEL_VERSION") - # If installing kernel doesn't have crashkernel.default, just exit. - [[ -z "$inst_ck_default" ]] && exit 0 - - boot_kernel=$(uname -r) - boot_ck_cmdline=$(sed -n -e "s/^.*\(crashkernel=\S*\).*$/\1/p" /proc/cmdline) - highest_ck_default_kver=$(get_highest_ck_default_kver) - highest_ck_default=$(get_ck_default "$highest_ck_default_kver") - - # Try update /etc/default/grub if present, else grub2-mkconfig could - # override crashkernel value. - grub_etc_ck=$(get_grub_etc_ck) - if [[ -n "$grub_etc_ck" ]]; then - if [[ -z "$highest_ck_default_kver" ]]; then - # None of installed kernel have a crashkernel.default, - # check for 'crashkernel=auto' in case of legacy kernel - [[ "$grub_etc_ck" == "crashkernel=auto" ]] && \ - set_grub_ck "$inst_ck_default" - else - # There is a valid crashkernel.default, check if installing kernel - # have a higher version and grub config is using default value - ver_lt "$highest_ck_default_kver" "$KERNEL_VERSION" && \ - [[ "$grub_etc_ck" == "$highest_ck_default" ]] && \ - [[ "$grub_etc_ck" != "$inst_ck_default" ]] && \ - set_grub_ck "$inst_ck_default" - fi - fi - - # Exit if crashkernel is not used in current cmdline - [[ -z $boot_ck_cmdline ]] && exit 0 - - # Get current boot kernel's default value - boot_ck_default=$(get_ck_default "$boot_kernel") - if [[ $boot_ck_cmdline == "crashkernel=auto" ]]; then - # Legacy RHEL kernel defaults to "auto" - boot_ck_default="$boot_ck_cmdline" - fi - - # If boot kernel doesn't have a crashkernel.default, check - # if it's using any installed kernel's crashkernel.default - if [[ -z $boot_ck_default ]]; then - [[ $(get_highest_ck_default_kver "$boot_ck_cmdline") ]] && boot_ck_default="$boot_ck_cmdline" - fi - - # If boot kernel is using a default crashkernel, update - # installing kernel's crashkernel to new default value - if [[ "$boot_ck_cmdline" != "$inst_ck_default" ]] && [[ "$boot_ck_cmdline" == "$boot_ck_default" ]]; then - set_kernel_ck "$KERNEL_VERSION" "$inst_ck_default" - fi - - exit 0 - ;; -remove) - # If grub default value is upgraded when this kernel was installed, try downgrade it - grub_etc_ck=$(get_grub_etc_ck) - [[ $grub_etc_ck ]] || exit 0 - - removing_ck_conf=$(get_ck_default "$KERNEL_VERSION") - [[ $removing_ck_conf ]] || exit 0 - - highest_ck_default_kver=$(get_highest_ck_default_kver) || exit 0 - highest_ck_default=$(get_ck_default "$highest_ck_default_kver") - [[ $highest_ck_default ]] || exit 0 - - if ver_lt "$highest_ck_default_kver" "$KERNEL_VERSION"; then - if [[ $grub_etc_ck == "$removing_ck_conf" ]] && [[ $grub_etc_ck != "$highest_ck_default" ]]; then - set_grub_ck "$highest_ck_default" - fi - fi - + kdumpctl reset-crashkernel-for-installed_kernel "$KERNEL_VERSION" exit 0 ;; esac diff --git a/kdumpctl b/kdumpctl index 07e6f8b..66eefa5 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1576,6 +1576,32 @@ reset_crashkernel_after_update() done } +reset_crashkernel_for_installed_kernel() +{ + local _installed_kernel _running_kernel _crashkernel _crashkernel_running + local _dump_mode_running _fadump_val_running + + if ! _installed_kernel=$(_find_kernel_path_by_release "$1"); then + exit 1 + fi + + if ! _running_kernel=$(_get_current_running_kernel_path); then + derror "Couldn't find current running kernel" + exit + fi + + _crashkernel=$(get_grub_kernel_boot_parameter "$_installed_kernel" crashkernel) + _crashkernel_running=$(get_grub_kernel_boot_parameter "$_running_kernel" crashkernel) + _dump_mode_running=$(get_dump_mode_by_kernel "$_running_kernel") + _fadump_val_running=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + + if [[ $_crashkernel != "$_crashkernel_running" ]]; then + if _update_grub "$_installed_kernel" "$_crashkernel_running" "$_dump_mode_running" "$_fadump_val_running"; then + echo "kexec-tools has reset $_installed_kernel to use the new default crashkernel value $_crashkernel_running" + fi + fi +} + if [[ ! -f $KDUMP_CONFIG_FILE ]]; then derror "Error: No kdump config file found!" exit 1 @@ -1641,6 +1667,11 @@ main() reset_crashkernel_after_update fi ;; + reset-crashkernel-for-installed_kernel) + if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then + reset_crashkernel_for_installed_kernel "$2" + fi + ;; *) dinfo $"Usage: $0 {estimate|start|stop|status|restart|reload|rebuild|reset-crashkernel|propagate|showmem}" exit 1 From ddd428a1d0d72bee2a8459b1a81541bcd0676873 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 15 Dec 2021 21:45:18 +0800 Subject: [PATCH 177/454] set up kernel crashkernel for osbuild in kernel hook osbuild is a tool to build OS images. It uses bwrap to install packages inside a sandbox/container. Since the kernel package recommends kexec-tools which in turn recommends grubby, the installation order would be grubby -> kexec-tools -> kernel. So we can use the kernel hook 92-crashkernel.install provided by kexec-tools to set up kernel crashkernel for the target OS image. But in osbuild's case, there is no current running kernel and running `uname -r` in the container/sandbox actually returns the host kernel release. To set up kernel crashkernel for the OS image built by osbuild, a different logic is needed. We will check if kernel hook is running inside the osbuild container then set up kernel crashkernel only if osbuild hasn't specified a custome value. osbuild exposes [1] the container=bwrap-osbuild environment variable. According to [2], the environment variable is not inherited down the process tree, so we need to check /proc/1/environ to detect this environment variable to tell if the kernel hook is running inside a bwrap-osbuild container. After that we need to know if osbuild wants to use custom crashkernel value. This is done by checking if /etc/kernel/cmdline has crashkernel set [3]. /etc/kernel/cmdline is written before packages are installed. [1] https://github.com/osbuild/osbuild/pull/926 [2] https://systemd.io/CONTAINER_INTERFACE/ [3] https://bugzilla.redhat.com/show_bug.cgi?id=2024976#c5 Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kdumpctl b/kdumpctl index 66eefa5..a17bb34 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1576,6 +1576,11 @@ reset_crashkernel_after_update() done } +_is_osbuild() +{ + [[ $(sed -n -E 's/.*(^|\s)container=(\S*).*/\2/p' < /proc/1/environ) == bwrap-osbuild ]] +} + reset_crashkernel_for_installed_kernel() { local _installed_kernel _running_kernel _crashkernel _crashkernel_running @@ -1585,6 +1590,11 @@ reset_crashkernel_for_installed_kernel() exit 1 fi + if _is_osbuild && ! grep -q crashkernel= /etc/kernel/cmdline; then + reset_crashkernel "--kernel=$_installed_kernel" + return + fi + if ! _running_kernel=$(_get_current_running_kernel_path); then derror "Couldn't find current running kernel" exit From 0e162120b61c9b29a5ecbe7f3e447484b0a27b39 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 13 Dec 2021 12:44:14 +0800 Subject: [PATCH 178/454] update crashkernel-howto Update crashkernel-howto since crashkernel.default has been removed. The documentation is also simplified as a result. Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- crashkernel-howto.txt | 125 +++++++----------------------------------- 1 file changed, 20 insertions(+), 105 deletions(-) diff --git a/crashkernel-howto.txt b/crashkernel-howto.txt index 20f50e0..1ba79ab 100644 --- a/crashkernel-howto.txt +++ b/crashkernel-howto.txt @@ -13,13 +13,14 @@ kdump after you updated the `crashkernel=` value or changed the dump target. Default crashkernel value ========================= -Latest kernel packages include a `crashkernel.default` file installed in kernel -modules folder, available as: +Latest kexec-tools provides "kdumpctl get-default-crashkernel" to retrieve +the default crashkernel value, - /usr/lib/modules//crashkernel.default + $ echo $(kdumpctl get-default-crashkernel) + 1G-4G:192M,4G-64G:256M,64G-102400T:512M -The content of the file will be taken as the default value of 'crashkernel=', or -take this file as a reference for setting crashkernel value manually. +It will be taken as the default value of 'crashkernel=', you can use +this value as a reference for setting crashkernel value manually. New installed system @@ -27,7 +28,7 @@ New installed system Anaconda is the OS installer which sets all the kernel boot cmdline on a newly installed system. If kdump is enabled during Anaconda installation, Anaconda -will use the `crashkernel.default` file as the default `crashkernel=` value on +will use the default crashkernel value as the default `crashkernel=` value on the newly installed system. Users can override the value during Anaconda installation manually. @@ -36,20 +37,11 @@ Users can override the value during Anaconda installation manually. Auto update of crashkernel boot parameter ========================================= -Following context in this section assumes all kernel packages have a -`crashkernel.default` file bundled, which is true for the latest official kernel -packages. For kexec-tools behavior with a kernel that doesn't have a -`crashkernel.default` file, please refer to the “Custom Kernel” section of this -doc. - -When `crashkernel=` is using the default value, kexec-tools will need to update -the `crashkernel=` value of new installed kernels, since the default value may -change in new kernel packages. - -kexec-tools does so by adding a kernel installation hook, which gets triggered -every time a new kernel is installed, so kexec-tools can do necessary checks and -updates. - +A new release of kexec-tools could update the default crashkernel value. +By default, kexec-tools would reset crashkernel to the new default value if it +detects old default crashkernel value is used by installed kernels. If you don't +want kexec-tools to update the old default crashkernel to the new default +crashkernel, you can change auto_reset_crashkernel to no in kdump.conf. Supported Bootloaders --------------------- @@ -59,92 +51,13 @@ on `grubby`. If other boot loaders are used, the user will have to update the `crashkernel=` value manually. -Updating kernel package ------------------------ - -When a new version of package kernel is released in the official repository, the -package will always come with a `crashkernel.default` file bundled. Kexec-tools -will act with following rules: - -If current boot kernel is using the default `crashkernel=` boot param value from -its `crashkernel.default` file, then kexec-tools will update new installed -kernel’s `crashkernel=` boot param using the value from the new installed -kernel’s `crashkernel.default` file. This ensures `crashkernel=` is always using -the latest default value. - -If current boot kernel's `crashkernel=` value is set to a non-default value, the -new installed kernel simply inherits this value. - -On systems using GRUB2 as the bootloader, each kernel has its own boot entry, -making it possible to set different `crashkernel=` boot param values for -different kernels. So kexec-tools won’t touch any already installed kernel's -boot param, only new installed kernel's `crashkernel=` boot param value will be -updated. - -But some utilities like `grub2-mkconfig` and `grubby` can override all boot -entry's boot params with the boot params value from the GRUB config file -`/etc/defaults/grub`, so kexec-tools will also update the GRUB config file in -case old `crashkernel=` value overrides new installed kernel’s boot param. - - -Downgrading kernel package --------------------------- - -When upgrading a kernel package, kexec-tools may update the `crashkernel=` value -in GRUB2 config file to the new value. So when downgrading the kernel package, -kexec-tools will also try to revert that update by setting GRUB2 config file’s -`crashkernel=` value back to the default value in the older kernel package. This -will only occur when the GRUB2 config file is using the default `crashkernel=` -value. - - -Custom kernel -============= - -To make auto crashkernel update more robust, kexec-tools will try to keep -tracking the default 'crashkernel=` value with kernels that don’t have a -`crashkernel.default` file, such kernels are referred to as “custom kernel” in -this doc. This is only a best-effort support to make it easier debugging and -testing the system. - -When installing a custom kernel that doesn’t have a `crashkernel.default` file, -the `crashkernel=` value will be simply inherited from the current boot kernel. - -When installing a new official kernel package and current boot kernel is a -custom kernel, since the boot kernel doesn’t have a `crashkernel.default` file, -kexec-tools will iterate installed kernels and check if the boot kernel -inherited the default value from any other existing kernels’ -`crashkernel.default` file. If a matching `crashkernel.default` file is found, -kexec-tools will update the new installed kernel `crashkernel=` boot param using -the value from the new installed kernel’s `crashkernel.default` file, ensures -the auto crashkernel value update won’t break over one or two custom kernel -installations. - -It is possible that the auto crashkernel value update will fail when custom -kernels are used. One example is a custom kernel inheriting the default -`crashkernel=` value from an older official kernel package, but later that -kernel package is uninstalled. So when booted with the custom kernel, -kexec-tools can't determine if the boot kernel is inheriting a default -`crashkernel=` value from any official build. In such a case, please refer to -the "Reset crashkernel to default value" section of this doc. - - Reset crashkernel to default value ================================== kexec-tools only perform the auto update of crashkernel value when it can confirm the boot kernel's crashkernel value is using its corresponding default -value or inherited from any installed kernel. - -kexec-tools may fail to determine if the boot kernel is using default -crashkernel value in some use cases: -- kexec-tools package is absent during a kernel package upgrade, and the new - kernel package’s `crashkernel.default` value has changed. -- Custom kernel is used and the kernel it inherits `crashkernel=` value from is - uninstalled. - -So it's recommended to reset the crashkernel value if users have uninstalled -kexec-tools or using a custom kernel. +value and auto_reset_crashkernel=yes in kdump.conf. In other cases, the user +can reset the crashkernel value by themselves. Reset using kdumpctl -------------------- @@ -152,21 +65,23 @@ Reset using kdumpctl To make it easier to reset the `crashkernel=` kernel cmdline to this default value properly, `kdumpctl` also provides a sub-command: - `kdumpctl reset-crashkernel []` + `kdumpctl reset-crashkernel [--kernel=path_to_kernel] [--reboot]` This command will read from the `crashkernel.default` file and reset bootloader's kernel cmdline to the default value. It will also update bootloader config if the bootloader has a standalone config file. User will have to reboot -the machine after this command to make it take effect. +the machine after this command to make it take effect if --reboot is not specified. +For ppc64le, an optional "[--fadump=[on|off|nocma]]" can also be specified to toggle +FADump on/off. Reset manually -------------- To reset the crashkernel value manually, it's recommended to use utils like `grubby`. A one liner script for resetting `crashkernel=` value of all installed -kernels to current boot kernel's crashkernel.default` is: +kernels to current boot kernel's crashkernel.default` is: - grubby --update-kernel ALL --args "$(cat /usr/lib/modules/$(uname -r)/crashkernel.default)" + grubby --update-kernel ALL --args "crashkernel=$(kdumpctl get-default-crashkernel)" Estimate crashkernel ==================== From 0311f6e25bec9994de2c6b156b5a568583aa8aae Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Wed, 5 Jan 2022 17:42:12 +0800 Subject: [PATCH 179/454] Set zstd as the default compression method for kdump initrd zstd has better compression ratio and time consumption balance. When no customized compression method specified in kdump.conf, we will use zstd as the default compression method. **The test method: I installed kexec-tools with and without the patch, executing the following command for 4 times, and calculate the averange time: $ rm -f /boot/initramfs-*kdump.img && time kdumpctl rebuild && \ ls -ail /boot/initramfs-*kdump.img **The test result: Bare metal x86_64 machine: dracut with squash module zlib lzo xz lz4 zstd real 10.6282 11.0398 11.395 8.6424 10.1676 user 9.8932 11.9072 14.2304 2.8286 8.6468 sys 3.523 3.4626 3.6028 3.5 3.4942 size of kdump.img 30575616 31419392 27102208 36666368 29236224 dracut without squash module zlib lzo xz lz4 zstd real 9.509 19.4876 11.6724 9.0338 10.267 user 10.6028 14.516 17.8662 4.0476 9.0936 sys 2.942 2.9184 3.0662 2.9232 3.0662 size of kdump.img 19247949 19958120 14505056 21112544 17007764 PowerVM hosted ppc64le VM: dracut with squash module | dracut without sqaush module zlib zstd | zlib zstd real 10.6742 10.7572 | 9.7676 10.5722 user 18.754 19.8338 | 20.7932 13.179 sys 1.8358 1.864 | 1.637 1.663 | size of | kdump.img 36917248 35467264 | 21441323 19007108 **discussion zstd has a better compression ratio and time consumption balance. v1 -> v2: Use kdump_get_conf_val() to get dracut_args values of kdump.conf v2 -> v3: Attached testing benchmark v3 -> v4: Re-measured and re-attached the testing benchmark of x86_64 and ppc64le. Changed regex '.*[[:space:]]' to '(^|[[:space:]])' v4 -> v5: Attacked lzo/xz/lz4 testing benchmark. v5 -> v6: Add zstd as required in kexec-tools.spec Hello Coiby, you may use "RELEASE=34 make test-run", for CONFIG_RD_ZSTD is enabled since fc-cloud-34 Acked-by: Coiby Xu Signed-off-by: Tao Liu --- kdump-lib.sh | 6 ++++++ kexec-tools.spec | 1 + mkdumprd | 4 ++++ mkfadumprd | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index b28db44..2d0e061 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -443,6 +443,12 @@ is_wdt_active() return 1 } +have_compression_in_dracut_args() +{ + [[ "$(kdump_get_conf_val dracut_args)" =~ \ + (^|[[:space:]])--(gzip|bzip2|lzma|xz|lzo|lz4|zstd|no-compress|compress)([[:space:]]|$) ]] +} + # If "dracut_args" contains "--mount" information, use it # directly without any check(users are expected to ensure # its correctness). diff --git a/kexec-tools.spec b/kexec-tools.spec index b2a0e20..381a13d 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -70,6 +70,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool +Requires: zstd Recommends: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel libzstd-devel diff --git a/mkdumprd b/mkdumprd index d87d588..9c26ecc 100644 --- a/mkdumprd +++ b/mkdumprd @@ -431,6 +431,10 @@ done <<< "$(kdump_read_conf)" handle_default_dump_target +if ! have_compression_in_dracut_args; then + add_dracut_arg "--compress" "zstd" +fi + if [[ -n $extra_modules ]]; then add_dracut_arg "--add-drivers" "$extra_modules" fi diff --git a/mkfadumprd b/mkfadumprd index b890f83..16fdacc 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -62,6 +62,10 @@ if is_squash_available; then _dracut_isolate_args+=(--add squash) fi +if ! have_compression_in_dracut_args; then + _dracut_isolate_args+=(--compress zstd) +fi + if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then perror_exit "mkfadumprd: failed to setup '$TARGET_INITRD' with dump capture capability" fi From 2bd59ee156ee7646e4c9fcacb72667e016e07ffe Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 6 Jan 2022 11:46:54 +0800 Subject: [PATCH 180/454] kdump-lib.sh: Escape '|' for 'failure_action|default' in is_dump_to_rootfs The '|' in 'failure_action|default' should be replaced with '\|' when passed to kdump_get_conf_val function. Because '|' needs to be escaped to mean OR operation in sed regex, otherwise it will consider 'failure_action|default' as a whole string. Fixes: ab1ef78 ("kdump-lib.sh: use kdump_get_conf_val to read config values") v1 -> v2: Rephased the commit message. Replaced " with '. Signed-off-by: Tao Liu Acked-by: Coiby Xu --- kdump-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 2d0e061..1db55fd 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -108,7 +108,7 @@ get_block_dump_target() is_dump_to_rootfs() { - [[ $(kdump_get_conf_val "failure_action|default") == dump_to_rootfs ]] + [[ $(kdump_get_conf_val 'failure_action\|default') == dump_to_rootfs ]] } get_failure_action_target() From d5c31605f364e258fdef60e8482498941644ad6a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 6 Jan 2022 09:48:17 +0800 Subject: [PATCH 181/454] use grep -s to suppress error messages about nonexistent or unreadable files When a file doesn't exist or isn't readable, grep complains as follows, grep: /proc/cmdline: No such file or directory grep: /etc/kernel/cmdline: No such file or directory /proc/cmdline doesn't exist when installing package for an OS image and /etc/kernel/cmdline may not exist if osbuild doesn't want set custom kernel cmdline. Use "-s" to suppress the error messages. Fixes: 0adb0f4 ("try to reset kernel crashkernel when kexec-tools updates the default crashkernel value") Fixes: ddd428a ("set up kernel crashkernel for osbuild in kernel hook") Signed-off-by: Coiby Xu Acked-by: Tao Liu --- kdumpctl | 2 +- kexec-tools.spec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kdumpctl b/kdumpctl index a17bb34..331af2f 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1590,7 +1590,7 @@ reset_crashkernel_for_installed_kernel() exit 1 fi - if _is_osbuild && ! grep -q crashkernel= /etc/kernel/cmdline; then + if _is_osbuild && ! grep -qs crashkernel= /etc/kernel/cmdline; then reset_crashkernel "--kernel=$_installed_kernel" return fi diff --git a/kexec-tools.spec b/kexec-tools.spec index 381a13d..dffcce0 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -261,7 +261,7 @@ mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{d %pre # save the old default crashkernel values to /tmp/ when upgrading the package -if ! grep -q "ostree" /proc/cmdline && [ $1 == 2 ] && grep -q get-default-crashkernel /usr/bin/kdumpctl; then +if ! grep -qs "ostree" /proc/cmdline && [ $1 == 2 ] && grep -q get-default-crashkernel /usr/bin/kdumpctl; then kdumpctl get-default-crashkernel kdump > /tmp/old_default_crashkernel 2>/dev/null %ifarch ppc64 ppc64le kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null @@ -303,7 +303,7 @@ fi # try to reset kernel crashkernel value to new default value when upgrading # the package -if ! grep -q "ostree" /proc/cmdline && [ $1 == 2 ]; then +if ! grep -qs "ostree" /proc/cmdline && [ $1 == 2 ]; then kdumpctl reset-crashkernel-after-update rm /tmp/old_default_crashkernel 2>/dev/null %ifarch ppc64 ppc64le From ae0cbdf34a51b6b7f12d11f62d45339130750d01 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 7 Jan 2022 10:45:40 +0800 Subject: [PATCH 182/454] fix "kdump: Invalid kdump config option auto_reset_crashkernel" error kdumpctl only accepts a specified set of options. Add auto_reset_crashkernel to this set. Fixes: 73ced7f ("introduce the auto_reset_crashkernel option to kdump.conf") Signed-off-by: Coiby Xu Acked-by: Tao Liu --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 331af2f..8107487 100755 --- a/kdumpctl +++ b/kdumpctl @@ -209,7 +209,7 @@ check_config() ext[234] | minix | btrfs | xfs | nfs | ssh) config_opt=_target ;; - sshkey | path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes) ;; + sshkey | path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; net | options | link_delay | disk_timeout | debug_mem_level | blacklist) derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." From 7de4a0d6c87375d6b980fce323e17e637296c0b0 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Mon, 10 Jan 2022 21:51:16 +0800 Subject: [PATCH 183/454] Set zstd as recommented for kexec-tools This patch will make zstd as recommended instead of required for kexec-tools. If zstd command/package is unavaliable, it can failback to invoke gzip when making kdump initramfs. Fixes: 0311f6e ("Set zstd as the default compression method for kdump initrd") Signed-off-by: Tao Liu Acked-by: Coiby Xu --- kdump-lib.sh | 5 +++++ kexec-tools.spec | 2 +- mkdumprd | 7 ++++++- mkfadumprd | 5 ++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 1db55fd..ca086d7 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -31,6 +31,11 @@ is_squash_available() done } +is_zstd_command_available() +{ + [[ -x "$(command -v zstd)" ]] +} + perror_exit() { derror "$@" diff --git a/kexec-tools.spec b/kexec-tools.spec index dffcce0..7419723 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -70,7 +70,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool -Requires: zstd +Recommends: zstd Recommends: grubby BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel libzstd-devel diff --git a/mkdumprd b/mkdumprd index 9c26ecc..593ec77 100644 --- a/mkdumprd +++ b/mkdumprd @@ -432,7 +432,12 @@ done <<< "$(kdump_read_conf)" handle_default_dump_target if ! have_compression_in_dracut_args; then - add_dracut_arg "--compress" "zstd" + # Here zstd is set as the default compression method. If squash module + # is available for dracut, libzstd will be used by mksquashfs. If + # squash module is unavailable, command zstd will be used instead. + if is_squash_available || is_zstd_command_available; then + add_dracut_arg "--compress" "zstd" + fi fi if [[ -n $extra_modules ]]; then diff --git a/mkfadumprd b/mkfadumprd index 16fdacc..86dfcee 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -62,8 +62,11 @@ if is_squash_available; then _dracut_isolate_args+=(--add squash) fi +# Same as setting zstd in mkdumprd if ! have_compression_in_dracut_args; then - _dracut_isolate_args+=(--compress zstd) + if is_squash_available || is_zstd_command_available; then + _dracut_isolate_args+=(--compress zstd) + fi fi if ! dracut --force --quiet "${_dracut_isolate_args[@]}" "$@" "$TARGET_INITRD"; then From 1e569fd8a88ea146ca31bd0ac467fe657521f9eb Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 13 Jan 2022 14:41:03 +0800 Subject: [PATCH 184/454] Release 2.0.23-2 --- kexec-tools.spec | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 7419723..849d09c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.23 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -399,6 +399,34 @@ done %endif %changelog +* Thu Jan 13 2022 Coiby - 2.0.23-2 +- fix "kdump: Invalid kdump config option auto_reset_crashkernel" error +- use grep -s to suppress error messages about nonexistent or unreadable files +- kdump-lib.sh: Escape '|' for 'failure_action|default' in is_dump_to_rootfs +- Set zstd as the default compression method for kdump initrd +- (origin/auto_reset_crashkernel, auto_reset_crashkernel) update crashkernel-howto +- set up kernel crashkernel for osbuild in kernel hook +- reset kernel crashkernel for the special case where the kernel is updated right after kexec-tools +- try to reset kernel crashkernel when kexec-tools updates the default crashkernel value +- introduce the auto_reset_crashkernel option to kdump.conf +- rewrite reset_crashkernel to support fadump and to used by RPM scriptlet +- fix incorrect usage of rpm-ostree to update kernel command line parameters +- add helper functions to get kernel path by kernel release and the path of current running kernel +- add helper functions to get dump mode +- add a helper function to read kernel cmdline parameter from grubby --info +- provide kdumpctl get-default-crashkernel for kdump_anaconda_addon and RPM scriptlet +- factor out kdump_get_arch_recommend_crashkernel +- update default crashkernel value +- kdumpctl: remove some legacy code +- dracut-early-kdump-module-setup.sh: install xargs and kdump-lib-initramfs.sh +- ppc64/ppc64le: drop cpu online rule in 40-redhat.rules in kdump initramfs +- kdump/ppc64: suppress the error message "Could not find a registered notification tool" from servicelog_notify +- add keytuils as a weak dependency for POWER +- Document/kexec-kdump-howto.txt: improve notes for kdump_pre and kdump_post scripts +- sysconfig: make kexec_file_load as default option on ppc64le +- sysconfig: make kexec_file_load as default option on aarch64 +- Enable zstd compression for makedumpfile in kexec-tools.spec + * Mon Nov 18 2021 Coiby - 2.0.23-1 - Update kexec-tools to 2.0.23 - Rebase makedumpfile to 1.7.0 From 72ef6929a6e309b0c9ded72442075a6ec773beb3 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 18 Jan 2022 10:42:00 +0800 Subject: [PATCH 185/454] move variable FENCE_KDUMP_SEND from kdump-lib.sh to kdump-lib-initramfs.sh Since kdump-lib-initramfs.sh is included by kdump-lib.sh, and FENCE_KDUMP_SEND is used by both 1st and 2nd kernel, moving FENCE_KDUMP_SEND from kdump-lib.sh to kdump-lib-initramfs.sh. Signed-off-by: Pingfan Liu Acked-by: Tao Liu --- kdump-lib-initramfs.sh | 2 ++ kdump-lib.sh | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index c1fd75f..9be0fe9 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -5,6 +5,8 @@ DEFAULT_PATH="/var/crash/" KDUMP_CONFIG_FILE="/etc/kdump.conf" +FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" +FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" # Read kdump config in well formated style kdump_read_conf() diff --git a/kdump-lib.sh b/kdump-lib.sh index ca086d7..0e64f22 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -5,8 +5,6 @@ . /usr/lib/kdump/kdump-lib-initramfs.sh -FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" -FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" is_fadump_capable() From c480be7ccf8d63bed81f167bb4da7645f68c52a7 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Wed, 12 Jan 2022 19:24:26 +0800 Subject: [PATCH 186/454] spec: add hostname.rpm into Recommends list kexec-tools runs hostname binary in the case of fence_kdump. Since this is a trival dependency and should not block the kexec-tools installation if non-existent, using weak-dependency to resolve it. Signed-off-by: Pingfan Liu Acked-by: Tao Liu --- kexec-tools.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/kexec-tools.spec b/kexec-tools.spec index 849d09c..9f7118b 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -72,6 +72,7 @@ Requires: dracut-squash >= 050 Requires: ethtool Recommends: zstd Recommends: grubby +Recommends: hostname BuildRequires: make BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel libzstd-devel BuildRequires: pkgconfig intltool gettext From bb380a92fa65e69a2303cd8c99d47165faa39112 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Thu, 20 Jan 2022 14:26:44 +0000 Subject: [PATCH 187/454] - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 9f7118b..a1fbb97 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.23 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -400,6 +400,9 @@ done %endif %changelog +* Thu Jan 20 2022 Fedora Release Engineering - 2.0.23-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild + * Thu Jan 13 2022 Coiby - 2.0.23-2 - fix "kdump: Invalid kdump config option auto_reset_crashkernel" error - use grep -s to suppress error messages about nonexistent or unreadable files From f4ab396574c7842ccbb366e95f8445e44e2b5f0f Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 30 Dec 2021 11:26:42 +0800 Subject: [PATCH 188/454] selftest: run-test.sh: wait for subprocess instead of kill it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When run tests with 2 VMs, for example nfs/ssh kdump tests, client VM will do the crash and dump, server VM will do vmcore saving and if-vmcore-exists check. Previously, when client VM finishes running, run-test.sh will kill the lead background process, and then check if server VM has outputted "TEST PASSED" or "TEST FAILED" string. However it didn't wait for server VM to finish. As a result, the server VM's final outputs are not collected and checked, leaving the test result as "TEST RESULT NOT FOUND" sometimes. For example, the following is the pstree status of $(jobs -p) before it gets killed. We can see the server VM is still running: run-test.sh,172455 /root/kexec-tools/tests/scripts/run-test.sh --console nfs-early-kdump └─run-test.sh,172457 /root/kexec-tools/tests/scripts/run-test.sh --console... └─timeout,172480 --foreground 10m /root/kexec-tools/tests/scripts/run-qemu... └─qemu-system-x86,172481 -enable-kvm -cpu host -nodefaults... ├─{qemu-system-x86},172489 ├─{qemu-system-x86},172492 ├─{qemu-system-x86},172493 ├─{qemu-system-x86},172628 └─{qemu-system-x86},172629 In this patch, we will wait for $(jobs -p) to finish, in order to get the complete output of test results. Signed-off-by: Tao Liu Acked-by: Coiby Xu --- tests/scripts/run-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/run-test.sh b/tests/scripts/run-test.sh index c3e94a3..1501db4 100755 --- a/tests/scripts/run-test.sh +++ b/tests/scripts/run-test.sh @@ -140,7 +140,7 @@ for test_case in $testcases; do if [ $console -eq 1 ]; then run_test_sync $script | tee $(get_test_console_file $script) - [ -n "$(jobs -p)" ] && kill $(jobs -p) + [ -n "$(jobs -p)" ] && wait $(jobs -p) else $(run_test_sync $script > $(get_test_console_file $script)) & watch_test_outputs $test_outputs From aa9e70349b9c1735a52549f863efc9b3dd87f94c Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 30 Dec 2021 11:26:43 +0800 Subject: [PATCH 189/454] selftest: Add early kdump test This patch will introduce early kdump test. It reuses the code of nfs kdump test, in order to setup 2 seperated VMs, one(the client) for trigger the early kdump and crash, the other(the server) for saving vmcore and check if vmcore exists. In order to minimize the repetted code, a soft link is made to copy the same server side code. Signed-off-by: Tao Liu Acked-by: Coiby Xu --- .../testcases/nfs-early-kdump/0-server.sh | 1 + .../testcases/nfs-early-kdump/1-client.sh | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 120000 tests/scripts/testcases/nfs-early-kdump/0-server.sh create mode 100755 tests/scripts/testcases/nfs-early-kdump/1-client.sh diff --git a/tests/scripts/testcases/nfs-early-kdump/0-server.sh b/tests/scripts/testcases/nfs-early-kdump/0-server.sh new file mode 120000 index 0000000..3f888ce --- /dev/null +++ b/tests/scripts/testcases/nfs-early-kdump/0-server.sh @@ -0,0 +1 @@ +../nfs-kdump/0-server.sh \ No newline at end of file diff --git a/tests/scripts/testcases/nfs-early-kdump/1-client.sh b/tests/scripts/testcases/nfs-early-kdump/1-client.sh new file mode 100755 index 0000000..dfef4d8 --- /dev/null +++ b/tests/scripts/testcases/nfs-early-kdump/1-client.sh @@ -0,0 +1,46 @@ +# Executed before VM starts +on_build() { + img_inst_pkg "nfs-utils" + img_add_qemu_cmd "-nic socket,connect=127.0.0.1:8010,mac=52:54:00:12:34:57" +} + +on_test() { + local boot_count=$(get_test_boot_count) + local nfs_server=192.168.77.1 + local earlykdump_path="/usr/lib/dracut/modules.d/99earlykdump/early-kdump.sh" + local tmp_file="/tmp/.tmp-file" + + if [[ ! -f $earlykdump_path ]]; then + test_failed "early-kdump.sh not exist!" + fi + + if [ $boot_count -eq 1 ]; then + cat << EOF > /etc/kdump.conf +nfs $nfs_server:/srv/nfs +core_collector makedumpfile -l --message-level 7 -d 31 +final_action poweroff +EOF + + while ! ping -c 1 $nfs_server -W 1; do + sleep 1 + done + + kdumpctl start \ + || test_failed "Failed to start kdump" + grubby --update-kernel=ALL --args=rd.earlykdump + + cat << EOF > $tmp_file +echo 1 > /proc/sys/kernel/sysrq +echo c > /proc/sysrq-trigger +EOF + sed -i "/early_kdump_load$/r $tmp_file" $earlykdump_path + dracut -f --add earlykdump + kdumpctl restart \ + || test_failed "Failed to start earlykdump" + + sync + reboot + else + test_failed "Unexpected reboot" + fi +} From 748eb3a2a6b41bc74748f1f1845b91b77548e1d8 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Sun, 9 Jan 2022 18:03:35 +0800 Subject: [PATCH 190/454] spec: only install mkfadumprd for ppc fadump is a ppc only feature, mkfadumprd is only needed for fadump, drop it for other arch. Reviewed-by: Philipp Rudo Signed-off-by: Kairui Song --- kexec-tools.spec | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index a1fbb97..0ef93f9 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -188,7 +188,6 @@ SYSCONFIG=$RPM_SOURCE_DIR/kdump.sysconfig.%{_target_cpu} install -m 644 $SYSCONFIG $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/kdump install -m 755 %{SOURCE7} $RPM_BUILD_ROOT/usr/sbin/mkdumprd -install -m 755 %{SOURCE32} $RPM_BUILD_ROOT/usr/sbin/mkfadumprd install -m 644 %{SOURCE8} $RPM_BUILD_ROOT%{_sysconfdir}/kdump.conf install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8 install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8 @@ -197,6 +196,7 @@ install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh install -m 755 %{SOURCE23} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh install -m 755 %{SOURCE31} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-logger.sh %ifarch ppc64 ppc64le +install -m 755 %{SOURCE32} $RPM_BUILD_ROOT/usr/sbin/mkfadumprd install -m 755 %{SOURCE35} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-migrate-action.sh install -m 755 %{SOURCE36} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-restart.sh %endif @@ -352,8 +352,10 @@ done %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 /usr/sbin/makedumpfile %endif -/usr/sbin/mkdumprd +%ifarch ppc64 ppc64le /usr/sbin/mkfadumprd +%endif +/usr/sbin/mkdumprd /usr/sbin/vmcore-dmesg %{_bindir}/* %{_datadir}/kdump From 99de77bba7ff7668edab3da723aad7c1c8395b5f Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Fri, 21 Jan 2022 16:08:47 +0800 Subject: [PATCH 191/454] Revert "Remove trace_buf_size and trace_event from the kernel bootparameters of the kdump kernel" There is a mechanism to keep memory consumption minimum, i.e. equal to trace_buf_size=1, until tracing by ftrace is actually started: tracing: keep ring buffer to minimum size till used https://github.com/torvalds/linux/commit/73c5162aa362a543793f4a957c6c536dcbaa89ce Since ftrace is usually never used in the kdump 2nd kernel, the kdump 2nd kernel behaves in the same way with or without trace_buf_size=1. So the issue which the patch want to solve never exists. Let's revert the patch for better maintainance and avoid confusion. ref link: https://bugzilla.redhat.com/show_bug.cgi?id=2034501#c20 This reverts commit f39000f. Signed-off-by: Tao Liu Acked-by: Coiby Xu --- kdump-lib.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 0e64f22..3256581 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -782,10 +782,6 @@ prepare_cmdline() fi done - # Remove trace_buf_size, trace_event - cmdline=$(remove_cmdline_param "$cmdline" trace_buf_size trace_event) - cmdline="${cmdline} trace_buf_size=1" - echo "$cmdline" } From ca5a33855ff637d53c70e71282e73f3c67d85c86 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Tue, 25 Jan 2022 10:54:49 +0100 Subject: [PATCH 192/454] s390: handle R_390_PLT32DBL reloc entries in machine_apply_elf_rel() Resolves: bz2025860 Upstream: git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git commit 186e7b0752d8fce1618fa37519671c834c46340e Author: Alexander Egorenkov Date: Wed Dec 15 18:48:53 2021 +0100 s390: handle R_390_PLT32DBL reloc entries in machine_apply_elf_rel() Starting with gcc 11.3, the C compiler will generate PLT-relative function calls even if they are local and do not require it. Later on during linking, the linker will replace all PLT-relative calls to local functions with PC-relative ones. Unfortunately, the purgatory code of kexec/kdump is not being linked as a regular executable or shared library would have been, and therefore, all PLT-relative addresses remain in the generated purgatory object code unresolved. This in turn lets kexec-tools fail with "Unknown rela relocation: 0x14 0x73c0901c" for such relocation types. Furthermore, the clang C compiler has always behaved like described above and this commit should fix the purgatory code built with the latter. Because the purgatory code is no regular executable or shared library, contains only calls to local functions and has no PLT, all R_390_PLT32DBL relocation entries can be resolved just like a R_390_PC32DBL one. * https://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_zSeries/x1633.html#AEN1699 Relocation entries of purgatory code generated with gcc 11.3 ------------------------------------------------------------ $ readelf -r purgatory/purgatory.o Relocation section '.rela.text' at offset 0x6e8 contains 27 entries: Offset Info Type Sym. Value Sym. Name + Addend 00000000000c 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 00000000001a 001000000014 R_390_PLT32DBL 0000000000000000 sha256_starts + 2 000000000030 001100000014 R_390_PLT32DBL 0000000000000000 sha256_update + 2 000000000046 001200000014 R_390_PLT32DBL 0000000000000000 sha256_finish + 2 000000000050 000300000013 R_390_PC32DBL 0000000000000000 .data + 102 00000000005a 001300000014 R_390_PLT32DBL 0000000000000000 memcmp + 2 ... 000000000118 001600000014 R_390_PLT32DBL 0000000000000000 setup_arch + 2 00000000011e 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 00000000012c 000f00000014 R_390_PLT32DBL 0000000000000000 verify_sha256_digest + 2 000000000142 001700000014 R_390_PLT32DBL 0000000000000000 post_verification[...] + 2 Relocation entries of purgatory code generated with gcc 11.2 ------------------------------------------------------------ $ readelf -r purgatory/purgatory.o Relocation section '.rela.text' at offset 0x6e8 contains 27 entries: Offset Info Type Sym. Value Sym. Name + Addend 00000000000e 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 00000000001c 001000000013 R_390_PC32DBL 0000000000000000 sha256_starts + 2 000000000036 001100000013 R_390_PC32DBL 0000000000000000 sha256_update + 2 000000000048 001200000013 R_390_PC32DBL 0000000000000000 sha256_finish + 2 000000000052 000300000013 R_390_PC32DBL 0000000000000000 .data + 102 00000000005c 001300000013 R_390_PC32DBL 0000000000000000 memcmp + 2 ... 00000000011a 001600000013 R_390_PC32DBL 0000000000000000 setup_arch + 2 000000000120 000300000013 R_390_PC32DBL 0000000000000000 .data + 122 000000000130 000f00000013 R_390_PC32DBL 0000000000000000 verify_sha256_digest + 2 000000000146 001700000013 R_390_PC32DBL 0000000000000000 post_verification[...] + 2 Corresponding s390 kernel discussion: * https://lore.kernel.org/linux-s390/20211208105801.188140-1-egorenar@linux.ibm.com/T/#u Signed-off-by: Alexander Egorenkov Reported-by: Tao Liu Suggested-by: Philipp Rudo Reviewed-by: Philipp Rudo [hca@linux.ibm.com: changed commit message as requested by Philipp Rudo] Signed-off-by: Heiko Carstens Signed-off-by: Simon Horman v2: - Moved patch 601 -> 401 Signed-off-by: Philipp Rudo Acked-by: Coiby Xu --- ...oc_entries_in_machine_apply_elf_rel_.patch | 95 +++++++++++++++++++ kexec-tools.spec | 3 + 2 files changed, 98 insertions(+) create mode 100644 kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch diff --git a/kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch b/kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch new file mode 100644 index 0000000..10bc5ef --- /dev/null +++ b/kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch @@ -0,0 +1,95 @@ +commit 186e7b0752d8fce1618fa37519671c834c46340e +Author: Alexander Egorenkov +Date: Wed Dec 15 18:48:53 2021 +0100 + + s390: handle R_390_PLT32DBL reloc entries in machine_apply_elf_rel() + + Starting with gcc 11.3, the C compiler will generate PLT-relative function + calls even if they are local and do not require it. Later on during linking, + the linker will replace all PLT-relative calls to local functions with + PC-relative ones. Unfortunately, the purgatory code of kexec/kdump is + not being linked as a regular executable or shared library would have been, + and therefore, all PLT-relative addresses remain in the generated purgatory + object code unresolved. This in turn lets kexec-tools fail with + "Unknown rela relocation: 0x14 0x73c0901c" for such relocation types. + + Furthermore, the clang C compiler has always behaved like described above + and this commit should fix the purgatory code built with the latter. + + Because the purgatory code is no regular executable or shared library, + contains only calls to local functions and has no PLT, all R_390_PLT32DBL + relocation entries can be resolved just like a R_390_PC32DBL one. + + * https://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_zSeries/x1633.html#AEN1699 + + Relocation entries of purgatory code generated with gcc 11.3 + ------------------------------------------------------------ + + $ readelf -r purgatory/purgatory.o + + Relocation section '.rela.text' at offset 0x6e8 contains 27 entries: + Offset Info Type Sym. Value Sym. Name + Addend + 00000000000c 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 + 00000000001a 001000000014 R_390_PLT32DBL 0000000000000000 sha256_starts + 2 + 000000000030 001100000014 R_390_PLT32DBL 0000000000000000 sha256_update + 2 + 000000000046 001200000014 R_390_PLT32DBL 0000000000000000 sha256_finish + 2 + 000000000050 000300000013 R_390_PC32DBL 0000000000000000 .data + 102 + 00000000005a 001300000014 R_390_PLT32DBL 0000000000000000 memcmp + 2 + ... + 000000000118 001600000014 R_390_PLT32DBL 0000000000000000 setup_arch + 2 + 00000000011e 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 + 00000000012c 000f00000014 R_390_PLT32DBL 0000000000000000 verify_sha256_digest + 2 + 000000000142 001700000014 R_390_PLT32DBL 0000000000000000 + post_verification[...] + 2 + + Relocation entries of purgatory code generated with gcc 11.2 + ------------------------------------------------------------ + + $ readelf -r purgatory/purgatory.o + + Relocation section '.rela.text' at offset 0x6e8 contains 27 entries: + Offset Info Type Sym. Value Sym. Name + Addend + 00000000000e 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 + 00000000001c 001000000013 R_390_PC32DBL 0000000000000000 sha256_starts + 2 + 000000000036 001100000013 R_390_PC32DBL 0000000000000000 sha256_update + 2 + 000000000048 001200000013 R_390_PC32DBL 0000000000000000 sha256_finish + 2 + 000000000052 000300000013 R_390_PC32DBL 0000000000000000 .data + 102 + 00000000005c 001300000013 R_390_PC32DBL 0000000000000000 memcmp + 2 + ... + 00000000011a 001600000013 R_390_PC32DBL 0000000000000000 setup_arch + 2 + 000000000120 000300000013 R_390_PC32DBL 0000000000000000 .data + 122 + 000000000130 000f00000013 R_390_PC32DBL 0000000000000000 verify_sha256_digest + 2 + 000000000146 001700000013 R_390_PC32DBL 0000000000000000 post_verification[...] + 2 + + Corresponding s390 kernel discussion: + * https://lore.kernel.org/linux-s390/20211208105801.188140-1-egorenar@linux.ibm.com/T/#u + + Signed-off-by: Alexander Egorenkov + Reported-by: Tao Liu + Suggested-by: Philipp Rudo + Reviewed-by: Philipp Rudo + [hca@linux.ibm.com: changed commit message as requested by Philipp Rudo] + Signed-off-by: Heiko Carstens + Signed-off-by: Simon Horman + +diff --git a/kexec/arch/s390/kexec-elf-rel-s390.c b/kexec/arch/s390/kexec-elf-rel-s390.c +index a5e1b73455785ae3bc3aa72b3beee13ae202e82f..91ba86a9991dad4271b834fc3b24861c40309e52 100644 +--- a/kexec/arch/s390/kexec-elf-rel-s390.c ++++ b/kexec/arch/s390/kexec-elf-rel-s390.c +@@ -56,6 +56,7 @@ void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), + case R_390_PC16: /* PC relative 16 bit. */ + case R_390_PC16DBL: /* PC relative 16 bit shifted by 1. */ + case R_390_PC32DBL: /* PC relative 32 bit shifted by 1. */ ++ case R_390_PLT32DBL: /* 32 bit PC rel. PLT shifted by 1. */ + case R_390_PC32: /* PC relative 32 bit. */ + case R_390_PC64: /* PC relative 64 bit. */ + val -= address; +@@ -63,7 +64,7 @@ void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), + *(unsigned short *) loc = val; + else if (r_type == R_390_PC16DBL) + *(unsigned short *) loc = val >> 1; +- else if (r_type == R_390_PC32DBL) ++ else if (r_type == R_390_PC32DBL || r_type == R_390_PLT32DBL) + *(unsigned int *) loc = val >> 1; + else if (r_type == R_390_PC32) + *(unsigned int *) loc = val; diff --git a/kexec-tools.spec b/kexec-tools.spec index 0ef93f9..aabb369 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -103,6 +103,7 @@ Requires: systemd-udev%{?_isa} # # Patches 401 through 500 are meant for s390 kexec-tools enablement # +Patch401: ./kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch # # Patches 501 through 600 are meant for ARM kexec-tools enablement @@ -126,6 +127,8 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} +%patch401 -p1 + %ifarch ppc %define archdef ARCH=ppc %endif From 6a3ce83a60c7107112d576223175410b180a41a0 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 19 Jan 2022 11:16:29 +0800 Subject: [PATCH 193/454] fix the error of parsing the container environ variable for osbuild The environment variable entries in /proc/[pid]/environ are separated by null bytes instead of by spaces. Update the sed regex to fix this issue. Note that, 1. this patch also fixes a issue which is kdumpctl would try to reset crashkernel even osbuild has provided custom crashkernel value. 2. kernel hook 92-crashkernel.install installed by kexec-tools is guaranteed to be ran by kernel-install. kexec-tools doesn't recommend kernel so there is no guarantee kernel is installed after kexec-tools. But dnf invokes kernel-install in the posttrans scriptlet (of kernel-core) which is always ran after all packages including kexec-tools and kernel in a dnf transaction. 3. To be able to do unit tests, the logic of reading environment variable has been extracted as a separate function. Fixes: ddd428a ("set up kernel crashkernel for osbuild in kernel hook") Signed-off-by: Coiby Xu Reviewed-by: Pingfan Liu Reviewed-by: Philipp Rudo --- kdumpctl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/kdumpctl b/kdumpctl index 8107487..3ccfa97 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1576,9 +1576,19 @@ reset_crashkernel_after_update() done } +# read the value of an environ variable from given environ file path +# +# The environment variable entries in /proc/[pid]/environ are separated +# by null bytes instead of by spaces. +read_proc_environ_var() +{ + local _environ_path=$1 _var=$2 + sed -n -E "s/.*(^|\x00)${_var}=([^\x00]*).*/\2/p" < "$_environ_path" +} + _is_osbuild() { - [[ $(sed -n -E 's/.*(^|\s)container=(\S*).*/\2/p' < /proc/1/environ) == bwrap-osbuild ]] + [[ $(read_proc_environ_var container /proc/1/environ) == bwrap-osbuild ]] } reset_crashkernel_for_installed_kernel() @@ -1590,8 +1600,10 @@ reset_crashkernel_for_installed_kernel() exit 1 fi - if _is_osbuild && ! grep -qs crashkernel= /etc/kernel/cmdline; then - reset_crashkernel "--kernel=$_installed_kernel" + if _is_osbuild; then + if ! grep -qs crashkernel= /etc/kernel/cmdline; then + reset_crashkernel "--kernel=$_installed_kernel" + fi return fi From c67a836cde781fecc8b785128132f4c8c2fd0190 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 25 Jan 2022 16:16:58 +0800 Subject: [PATCH 194/454] remove the upper bound of 102400T for the range in default crashkernel This patch makes the default crashkernel value consistent with previous one. Fixes: 105c016 ("factor out kdump_get_arch_recommend_crashkernel") Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 3256581..c6bdd2e 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -857,7 +857,6 @@ kdump_get_arch_recommend_crashkernel() fi fi - _ck_cmdline=${_ck_cmdline//-:/-102400T:} echo -n "$_ck_cmdline" } @@ -873,6 +872,7 @@ kdump_get_arch_recommend_size() fi sys_mem=$(get_system_size) _ck_cmdline=$(kdump_get_arch_recommend_crashkernel) + _ck_cmdline=${_ck_cmdline//-:/-102400T:} get_recommend_size "$sys_mem" "$ck_cmdline" } From 2df55984f66bc2a67c881eab0e33139d2ddc0461 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 26 Jan 2022 08:48:18 +0800 Subject: [PATCH 195/454] fix broken kdump_get_arch_recommend_size shellcheck finds the following problem, $ shellcheck kdump-lib.sh In kdump-lib.sh line 876: get_recommend_size "$sys_mem" "$ck_cmdline" ^---------^ SC2154: ck_cmdline is referenced but not assigned (did you mean '_ck_cmdline'?). s/ck_cmdline/_ck_cmdline to fix kdump_get_arch_recommend_size. Note s/sys_mem/_sys_mem as well to make the changes consistent. Fixes: 105c016 ("factor out kdump_get_arch_recommend_crashkernel") Signed-off-by: Coiby Xu Acked-by: Tao Liu --- kdump-lib.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index c6bdd2e..3e912cc 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -864,16 +864,16 @@ kdump_get_arch_recommend_crashkernel() # $1: kernel version, if not set, will defaults to $(uname -r) kdump_get_arch_recommend_size() { - local _ck_cmdline + local _ck_cmdline _sys_mem if ! [[ -r "/proc/iomem" ]]; then echo "Error, can not access /proc/iomem." return 1 fi - sys_mem=$(get_system_size) + _sys_mem=$(get_system_size) _ck_cmdline=$(kdump_get_arch_recommend_crashkernel) _ck_cmdline=${_ck_cmdline//-:/-102400T:} - get_recommend_size "$sys_mem" "$ck_cmdline" + get_recommend_size "$_sys_mem" "$_ck_cmdline" } # Print all underlying crypt devices of a block device From d6298a1dec83aa83df19cd994d7ace976822d3b9 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 26 Jan 2022 15:10:50 +0800 Subject: [PATCH 196/454] Release 2.0.23-4 --- kexec-tools.spec | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index aabb369..1750db0 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.23 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -405,6 +405,16 @@ done %endif %changelog +* Wed Jan 26 2022 Coiby - 2.0.23-4 +- fix broken kdump_get_arch_recommend_size +- remove the upper bound of 102400T for the range in default crashkernel +- fix the error of parsing the container environ variable for osbuild +- s390: handle R_390_PLT32DBL reloc entries in machine_apply_elf_rel() +- Revert "Remove trace_buf_size and trace_event from the kernel bootparameters of the kdump kernel" +- spec: only install mkfadumprd for ppc +- selftest: Add early kdump test +- selftest: run-test.sh: wait for subprocess instead of kill it + * Thu Jan 20 2022 Fedora Release Engineering - 2.0.23-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild From 5111c01334046dd4176d4446075b02106fb9db4a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 7 Feb 2022 08:08:01 +0800 Subject: [PATCH 197/454] fix the mistake of swapping function parameters of read_proc_environ_var _is_osbuild fails because it expects the 1st and 2nd function parameter to be the environment variable and environ file path respectively. Fix it by swapping the parameters in read_proc_environ_var. Note the osbuild environ file path is defined in _OSBUILD_ENVIRON_PATH so _is_osbuild can be unit-tested by overwriting _OSBUILD_ENVIRON_PATH. Fixes: 6a3ce83 ("fix the error of parsing the container environ variable for osbuild") Signed-off-by: Coiby Xu Reviewed-by: Pingfan Liu --- kdumpctl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 3ccfa97..bf74c75 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1580,15 +1580,19 @@ reset_crashkernel_after_update() # # The environment variable entries in /proc/[pid]/environ are separated # by null bytes instead of by spaces. +# +# $1: environment variable +# $2: environ file path read_proc_environ_var() { - local _environ_path=$1 _var=$2 + local _var=$1 _environ_path=$2 sed -n -E "s/.*(^|\x00)${_var}=([^\x00]*).*/\2/p" < "$_environ_path" } +_OSBUILD_ENVIRON_PATH='/proc/1/environ' _is_osbuild() { - [[ $(read_proc_environ_var container /proc/1/environ) == bwrap-osbuild ]] + [[ $(read_proc_environ_var container "$_OSBUILD_ENVIRON_PATH") == bwrap-osbuild ]] } reset_crashkernel_for_installed_kernel() From 41b8f9528c8ed89c68ad59750c18f032b5675a06 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 9 Feb 2022 08:04:39 +0800 Subject: [PATCH 198/454] fix incorrect usage of _get_all_kernels_from_grubby It's found that the kernel cmdline crashkernel=auto doesn't get updated when upgrading kexec-tools. This happens because _get_all_kernels_from_grubby is called with no argument by reset_crashkernel_after_update. When retrieving all kernel paths on the system, "grubby --info ALL" should be used. Fix this error by passing "ALL" argument. Fixes: 0adb0f4 ("try to reset kernel crashkernel when kexec-tools updates the default crashkernel value") Reported-by: Jie Li Signed-off-by: Coiby Xu Reviewed-by: Tao Liu --- kdumpctl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index bf74c75..9fd76ac 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1382,6 +1382,11 @@ _valid_grubby_kernel_path() [[ -n "$1" ]] && grubby --info="$1" > /dev/null 2>&1 } +# return all the kernel paths given a grubby kernel-path +# +# $1: kernel path accepted by grubby, e.g. DEFAULT, ALL, +# /boot/vmlinuz-`uname -r` +# return: kernel paths separated by space _get_all_kernels_from_grubby() { local _kernels _line _kernel_path _grubby_kernel_path=$1 @@ -1557,7 +1562,7 @@ reset_crashkernel_after_update() _crashkernel_vals[new_kdump]=$(get_default_crashkernel kdump) _crashkernel_vals[new_fadump]=$(get_default_crashkernel fadump) - for _kernel in $(_get_all_kernels_from_grubby); do + for _kernel in $(_get_all_kernels_from_grubby ALL); do _crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) if [[ $_crashkernel == auto ]]; then reset_crashkernel "--kernel=$_kernel" From 59fcb8ae5b13d776f5a1966173b57d6404699aae Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 14 Feb 2022 12:07:08 +0800 Subject: [PATCH 199/454] Release 2.0.23-5 Signed-off-by: Coiby Xu --- kexec-tools.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 1750db0..ac134da 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.23 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -405,6 +405,10 @@ done %endif %changelog +* Mon Feb 14 2022 Coiby - 2.0.23-5 +- fix incorrect usage of _get_all_kernels_from_grubby +- fix the mistake of swapping function parameters of read_proc_environ_var + * Wed Jan 26 2022 Coiby - 2.0.23-4 - fix broken kdump_get_arch_recommend_size - remove the upper bound of 102400T for the range in default crashkernel From 2bbc7512a2f2cf953ea047f54bd590d4d285b658 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Wed, 16 Feb 2022 14:26:38 +0800 Subject: [PATCH 200/454] kdump-lib.sh: Check the output of blkid with sed instead of eval Previously the output of blkid is not checked. If the output is empty, the eval will report the following error message: /lib/kdump/kdump-lib.sh: eval: line 925: syntax error near unexpected token `;' /lib/kdump/kdump-lib.sh: eval: line 925: `; echo $TYPE' For example, we can observe such a failing when blkid is invoked against a lvm thinpool block device: $ blkid -u filesystem,crypto -o export -- "/dev/block/253\:2" $ echo $? 2 $ udevadm info /dev/block/253\:2|grep S\: S: mapper/vg00-thinpoll_tmeta In this patch, we will use sed instead of eval, to output the fstype of block device if any. Signed-off-by: Tao Liu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 3e912cc..4ed5035 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -885,7 +885,8 @@ get_luks_crypt_dev() [[ -b /dev/block/$1 ]] || return 1 - _type=$(eval "$(blkid -u filesystem,crypto -o export -- "/dev/block/$1"); echo \$TYPE") + _type=$(blkid -u filesystem,crypto -o export -- "/dev/block/$1" | \ + sed -n -E "s/^TYPE=(.*)$/\1/p") [[ $_type == "crypto_LUKS" ]] && echo "$1" for _x in "/sys/dev/block/$1/slaves/"*; do From 311b5b100b512134cddb189f46c8bb85d74f9275 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 11 Feb 2022 13:11:17 +0800 Subject: [PATCH 201/454] update kernel crashkernel in posttrans RPM scriptlet when updating kexec-tools When doing in-place upgrading using leapp on x86_64, kdumpcl can't acquire instance lock when running in %post RPM scriplet on x86_64, localhost upgrade[1306]: /bin/kdumpctl: line 49: /var/lock/kdump: No such file or directory localhost upgrade[1306]: kdump: Create file lock failed and running "touch /var/lock/dkump" also fails with "No such file or directory". Thus kdumpctl can't be run in %post scriptlet. But kdumpctl can be run in %posttrans RPM scriplet. Besides, it's better to update crashkernel after the kernel has been updated. So let's update kernel crashkernel in the %posttrans scriptlet which will be run in the end of a transaction i.e. after the kernel has been updated. Note for %posttrans scriptlet, "$1 == 1" means both installing a new package and upgrading a package. [1] https://github.com/apptainer/singularity/issues/2386#issuecomment-474747054 Reported-by: Jie Li Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kexec-tools.spec | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index ac134da..6b7ef14 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -305,19 +305,6 @@ then mv /etc/sysconfig/kdump.new /etc/sysconfig/kdump fi -# try to reset kernel crashkernel value to new default value when upgrading -# the package -if ! grep -qs "ostree" /proc/cmdline && [ $1 == 2 ]; then - kdumpctl reset-crashkernel-after-update - rm /tmp/old_default_crashkernel 2>/dev/null -%ifarch ppc64 ppc64le - rm /tmp/old_default_crashkernel_fadump 2>/dev/null -%endif - # dnf would complain about the exit code not being 0. To keep it happy, - # always return 0 - : -fi - %postun %systemd_postun_with_restart kdump.service @@ -350,6 +337,21 @@ do fi done +%posttrans +# try to reset kernel crashkernel value to new default value when upgrading +# the package +if ! grep -qs "ostree" /proc/cmdline && [ $1 == 1 ]; then + kdumpctl reset-crashkernel-after-update + rm /tmp/old_default_crashkernel 2>/dev/null +%ifarch ppc64 ppc64le + rm /tmp/old_default_crashkernel_fadump 2>/dev/null +%endif + # dnf would complain about the exit code not being 0. To keep it happy, + # always return 0 + : +fi + + %files /usr/sbin/kexec %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 From 37f4f2c1f6f1304e1b58604a788c57c51508eead Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 15 Feb 2022 13:24:19 +0800 Subject: [PATCH 202/454] address the case where there are multiple values for the same kernel arg There is the case where there are multiple entries of the same parameter on the command line, e.g. GRUB_CMDLINE_LINUX="crashkernel=110M crashkernel=220M fadump=on crashkernel=330M". In such an situation _update_kernel_cmdline_in_grub_etc_default only updates/removes the last entry which is usually not what you want as the kernel (for crashkernel) takes the last entry it can find. Thus make sure the case with multiple entries of the same parameter is handled properly by removing all occurrences of given parameter first. Note 1. sed command group and conditional control has been used to get rid of grep. 2. Fully supporting kernel cmdline as documented in Documentation/admin-guide/kernel-parameters.rst is complex and in foreseeable future a full implementation is not needed. So simply document the unsupported cases instead. Fixes: 140da74 ("rewrite reset_crashkernel to support fadump and to used by RPM scriptlet") Reported-by: Philipp Rudo Suggested-by: Philipp Rudo Reviewed-by: Philipp Rudo --- kdumpctl | 54 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/kdumpctl b/kdumpctl index 9fd76ac..1c94405 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1399,25 +1399,49 @@ _get_all_kernels_from_grubby() } GRUB_ETC_DEFAULT="/etc/default/grub" -# modify the kernel command line parameter in default grub conf +# Update a kernel parameter in default grub conf +# +# If a value is specified, it will be inserted in the end. Otherwise it +# would remove given kernel parameter. +# +# Note this function doesn't address the following cases, +# 1. The kernel ignores everything on the command line after a '--'. So +# simply adding the new entry to the end will fail if the cmdline +# contains a --. +# 2. If the value for a parameter contains spaces it can be quoted using +# double quotes, for example param="value with spaces". This will +# break the [^[:space:]\"] regex for the value. +# 3. Dashes and underscores in the parameter name are equivalent. So +# some_parameter and some-parameter are identical. +# 4. Some parameters, e.g. efivar_ssdt, can be given multiple times. +# 5. Some kernel parameters, e.g. quiet, doesn't have value # # $1: the name of the kernel command line parameter -# $2: new value. If empty, the parameter would be removed -_update_kernel_cmdline_in_grub_etc_default() +# $2: new value. If empty, given parameter would be removed +_update_kernel_arg_in_grub_etc_default() { - local _para=$1 _val=$2 _para_val _regex + local _para=$1 _val=$2 _para_val if [[ -n $_val ]]; then _para_val="$_para=$_val" fi - _regex='^(GRUB_CMDLINE_LINUX=.*)([[:space:]"])'"$_para"'=[^[:space:]"]*(.*)$' - if grep -q -E "$_regex" "$GRUB_ETC_DEFAULT"; then - sed -i -E 's/'"$_regex"'/\1\2'"$_para_val"'\3/' "$GRUB_ETC_DEFAULT" - elif [[ -n $_para_val ]]; then - # If the kernel parameter doesn't exist, put it in the first - sed -i -E 's/^(GRUB_CMDLINE_LINUX=")/\1'"$_para_val"' /' "$GRUB_ETC_DEFAULT" - fi + # Update the command line /etc/default/grub, i.e. + # on the line that starts with 'GRUB_CMDLINE_LINUX=', + # 1) remove $para=$val if the it's the first arg + # 2) remove all occurences of $para=$val + # 3) insert $_para_val to end + # 4) remove duplicate spaces left over by 1) or 2) or 3) + # 5) remove space at the beginning of the string left over by 1) or 2) or 3) + # 6) remove space at the end of the string left over by 1) or 2) or 3) + sed -i -E "/^GRUB_CMDLINE_LINUX=/ { + s/\"${_para}=[^[:space:]\"]*/\"/g; + s/[[:space:]]+${_para}=[^[:space:]\"]*/ /g; + s/\"$/ ${_para_val}\"/ + s/[[:space:]]+/ /g; + s/(\")[[:space:]]+/\1/g; + s/[[:space:]]+(\")/\1/g; + }" "$GRUB_ETC_DEFAULT" } reset_crashkernel() @@ -1496,10 +1520,12 @@ reset_crashkernel() # - set the dump mode as kdump for non-ppc64le cases # - retrieved the default crashkernel value for given dump mode if [[ $_grubby_kernel_path == ALL && -n $_dump_mode ]]; then - _update_kernel_cmdline_in_grub_etc_default crashkernel "$_crashkernel" + _update_kernel_arg_in_grub_etc_default crashkernel "$_crashkernel" # remove the fadump if fadump is disabled - [[ $_fadump_val == off ]] && _fadump_val="" - _update_kernel_cmdline_in_grub_etc_default fadump "$_fadump_val" + if [[ $_fadump_val == off ]]; then + _fadump_val="" + fi + _update_kernel_arg_in_grub_etc_default fadump "$_fadump_val" fi # If kernel-path not specified, either From 6d4062a936694b7cab7e0c536414b4d5b6ab8668 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 16 Feb 2022 09:42:54 +0800 Subject: [PATCH 203/454] try to update the crashkernel in GRUB_ETC_DEFAULT after kexec-tools updates the default crashkernel value If GRUB_ETC_DEFAULT use crashkernel=auto or crashkernel=OLD_DEFAULT_CRASHKERNEL, it should be updated as well. Add a helper function to read kernel cmdline parameter from GRUB_ETC_DEFAULT. This function is used to read kernel cmdline parameter like fadump or crashkernel. Reviewed-by: Philipp Rudo --- kdumpctl | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/kdumpctl b/kdumpctl index 1c94405..ac6ffeb 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1444,6 +1444,16 @@ _update_kernel_arg_in_grub_etc_default() }" "$GRUB_ETC_DEFAULT" } +# Read the kernel arg in default grub conf. + +# Note reading a kernel parameter that doesn't have a value isn't supported. +# +# $1: the name of the kernel command line parameter +_read_kernel_arg_in_grub_etc_default() +{ + sed -n -E "s/^GRUB_CMDLINE_LINUX=.*[[:space:]\"]${1}=([^[:space:]\"]*).*$/\1/p" "$GRUB_ETC_DEFAULT" +} + reset_crashkernel() { local _opt _val _dump_mode _fadump_val _reboot _grubby_kernel_path _kernel _kernels @@ -1577,6 +1587,34 @@ reset_crashkernel() fi } +# update the crashkernel value in GRUB_ETC_DEFAULT if necessary +# +# called by reset_crashkernel_after_update and inherit its array variable +# _crashkernel_vals +update_crashkernel_in_grub_etc_default_after_update() +{ + local _crashkernel _fadump_val + local _dump_mode _old_default_crashkernel _new_default_crashkernel + + _crashkernel=$(_read_kernel_arg_in_grub_etc_default crashkernel) + + if [[ -z $_crashkernel ]]; then + return + fi + + _fadump_val=$(_read_kernel_arg_in_grub_etc_default fadump) + _dump_mode=$(get_dump_mode_by_fadump_val "$_fadump_val") + + _old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]} + _new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]} + + if [[ $_crashkernel == auto ]] || + [[ $_crashkernel == "$_old_default_crashkernel" && + $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then + _update_kernel_arg_in_grub_etc_default crashkernel "$_new_default_crashkernel" + fi +} + # shellcheck disable=SC2154 # false positive when dereferencing an array reset_crashkernel_after_update() { @@ -1605,6 +1643,8 @@ reset_crashkernel_after_update() fi fi done + + update_crashkernel_in_grub_etc_default_after_update } # read the value of an environ variable from given environ file path From 7141d044c8880815f308e61f612b710b7bc8a9a3 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Tue, 1 Mar 2022 13:09:00 +0800 Subject: [PATCH 204/454] kdumpctl: sync the $TARGET_INITRD after rebuild There is a system-wide sync call at the end of mkdumprd, move it to kdumpctl after rebuild initrd and add another one for mkfadumprd. Sync only the $TARGET_INITRD to avoid a system-wide sync taking too long on a system with high disk activity. Also update the sync in kdumpctl:restore_default_initrd which will mv the $DEFAULT_INITRD_BAK to $DEFAULT_INITRD. Signed-off-by: Lichen Liu Reviewed-by: Philipp Rudo --- kdumpctl | 4 +++- mkdumprd | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/kdumpctl b/kdumpctl index ac6ffeb..1869753 100755 --- a/kdumpctl +++ b/kdumpctl @@ -79,6 +79,7 @@ rebuild_fadump_initrd() return 1 fi + sync -f "$TARGET_INITRD" return 0 } @@ -100,6 +101,7 @@ rebuild_kdump_initrd() dwarn "Tips: If early kdump is enabled, also require rebuilding the system initramfs to make the changes take effect for early kdump." fi + sync -f "$TARGET_INITRD" return 0 } @@ -180,7 +182,7 @@ restore_default_initrd() rm -f $INITRD_CHECKSUM_LOCATION if mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD"; then derror "Restoring original initrd as fadump mode is disabled." - sync + sync -f "$DEFAULT_INITRD" fi fi fi diff --git a/mkdumprd b/mkdumprd index 593ec77..5996d50 100644 --- a/mkdumprd +++ b/mkdumprd @@ -458,7 +458,3 @@ if ! is_fadump_capable; then fi dracut "${dracut_args[@]}" "$@" - -_rc=$? -sync -exit $_rc From 8736aa5bb359e0fccbb07919e49f68c22299c55a Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 16:19:40 +0100 Subject: [PATCH 205/454] kdumpctl/estimate: Fix unnecessary warning do_estimate prints the warning that the reserved crashkernel is lower than the recommended one even then when both values are identical. This might cause confusion. So omit printing the warning when both values are equal. Signed-off-by: Philipp Rudo Acked-by: Coiby Xu --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 1869753..b7922a6 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1270,7 +1270,7 @@ do_estimate() done fi - if [[ $reserved_size -le $recommended_size ]]; then + if [[ $reserved_size -lt $recommended_size ]]; then echo "WARNING: Current crashkernel size is lower than recommended size $((recommended_size / size_mb))M." fi } From 5947707682e7de478aa1e1b41006ce50f84699cc Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:46:58 +0100 Subject: [PATCH 206/454] kdump-capture.service: switch to journal for stdout Using syslog for StandardOutput in a service file was deprecated in systemd v246 with commit f3dc6af20f ("core: automatically update StandardOuput=syslog to =journal (and similar for StandardError=)"). Thus the following warnings are printed in the crash kernel when creating a dump. systemd[1]: /usr/lib/systemd/system/kdump-capture.service:23: Standard output type syslog is obsolete, automatically updating to journal. Please update your unit file, and consider removing the setting altogether. systemd[1]: /usr/lib/systemd/system/kdump-capture.service:24: Standard output type syslog+console is obsolete, automatically updating to journal+console. Please update your unit file, and consider removing the setting altogether. Fix this by redirecting the stdout and stderr to the journal. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- dracut-kdump-capture.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dracut-kdump-capture.service b/dracut-kdump-capture.service index 3f20aba..7109169 100644 --- a/dracut-kdump-capture.service +++ b/dracut-kdump-capture.service @@ -20,8 +20,8 @@ Environment=NEWROOT=/sysroot Type=oneshot ExecStart=/bin/kdump.sh StandardInput=null -StandardOutput=syslog -StandardError=syslog+console +StandardOutput=journal +StandardError=journal+console KillMode=process RemainAfterExit=yes From aa9bb8f8cef734fb1f6ab36ccaaa8936edb4f467 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:46:59 +0100 Subject: [PATCH 207/454] kdump-lib: fix typo in variable name in prepare_kdump_bootinfo s/defaut/default/. While at it declare it with the other local variables as local. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdump-lib.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 4ed5035..5b1656e 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -640,7 +640,7 @@ prepare_kexec_args() prepare_kdump_bootinfo() { local boot_img boot_imglist boot_dirlist boot_initrdlist - local machine_id + local machine_id dir img default_initrd_base var_target_initrd_dir if [[ -z $KDUMP_KERNELVER ]]; then KDUMP_KERNELVER="$(uname -r)" @@ -677,8 +677,8 @@ prepare_kdump_bootinfo() boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" for initrd in $boot_initrdlist; do if [[ -f "$KDUMP_BOOTDIR/$initrd" ]]; then - defaut_initrd_base="$initrd" - DEFAULT_INITRD="$KDUMP_BOOTDIR/$defaut_initrd_base" + default_initrd_base="$initrd" + DEFAULT_INITRD="$KDUMP_BOOTDIR/$default_initrd_base" break fi done @@ -686,12 +686,12 @@ prepare_kdump_bootinfo() # Create kdump initrd basename from default initrd basename # initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img # initrd => initrdkdump - if [[ -z $defaut_initrd_base ]]; then + if [[ -z $default_initrd_base ]]; then kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img - elif [[ $defaut_initrd_base == *.* ]]; then - kdump_initrd_base=${defaut_initrd_base%.*}kdump.${DEFAULT_INITRD##*.} + elif [[ $default_initrd_base == *.* ]]; then + kdump_initrd_base=${default_initrd_base%.*}kdump.${DEFAULT_INITRD##*.} else - kdump_initrd_base=${defaut_initrd_base}kdump + kdump_initrd_base=${default_initrd_base}kdump fi # Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable From b49083126fcdd5be8cb7d84e0048ac2adddb6aed Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:00 +0100 Subject: [PATCH 208/454] kdumpctl: remove unnecessary uses of $? Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/kdumpctl b/kdumpctl index b7922a6..35fd6e0 100755 --- a/kdumpctl +++ b/kdumpctl @@ -86,7 +86,6 @@ rebuild_fadump_initrd() check_earlykdump_is_enabled() { grep -q -w "rd.earlykdump" /proc/cmdline - return $? } rebuild_kdump_initrd() @@ -117,8 +116,6 @@ rebuild_initrd() else rebuild_kdump_initrd fi - - return $? } #$1: the files to be checked with IFS=' ' @@ -584,7 +581,6 @@ check_rebuild() dinfo "Rebuilding $TARGET_INITRD" rebuild_initrd - return $? } # On ppc64le LPARs, the keys trusted by firmware do not end up in @@ -815,8 +811,6 @@ check_current_status() else check_current_kdump_status fi - - return $? } save_raw() @@ -945,7 +939,6 @@ check_dump_feasibility() fi check_kdump_feasibility - return $? } start_fadump() @@ -967,8 +960,6 @@ start_dump() else load_kdump fi - - return $? } check_failure_action_config() @@ -1077,7 +1068,7 @@ reload() if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then reload_fadump - return $? + return else if ! stop_kdump; then derror "Stopping kdump: [FAILED]" @@ -1141,7 +1132,7 @@ reload_fadump() # to handle such scenario. if stop_fadump; then start_fadump - return $? + return fi fi @@ -1180,7 +1171,6 @@ rebuild() dinfo "Rebuilding $TARGET_INITRD" rebuild_initrd - return $? } do_estimate() @@ -1787,5 +1777,3 @@ single_instance_lock exec 9<&- main "$@" ) - -exit $? From 7cd3f232d50c76bb5c6bf0b3175cc2c36c2f3351 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:01 +0100 Subject: [PATCH 209/454] kdump-lib-initramfs: merge definitions for default ssh key There are currently three identical definitions for the default ssh key. Combine them into one in kdump-lib-initramfs.sh. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- dracut-kdump.sh | 2 +- kdump-lib-initramfs.sh | 1 + kdumpctl | 2 +- mkdumprd | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index b69bc98..b17455a 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -22,7 +22,7 @@ FAILURE_ACTION="systemctl reboot -f" DATEDIR=$(date +%Y-%m-%d-%T) HOST_IP='127.0.0.1' DUMP_INSTRUCTION="" -SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" +SSH_KEY_LOCATION=$DEFAULT_SSHKEY DD_BLKSIZE=512 FINAL_ACTION="systemctl reboot -f" KDUMP_PRE="" diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 9be0fe9..84e6bf7 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -4,6 +4,7 @@ # not be the default shell. Any code added must be POSIX compliant. DEFAULT_PATH="/var/crash/" +DEFAULT_SSHKEY="/root/.ssh/kdump_id_rsa" KDUMP_CONFIG_FILE="/etc/kdump.conf" FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" diff --git a/kdumpctl b/kdumpctl index 35fd6e0..7b01cd3 100755 --- a/kdumpctl +++ b/kdumpctl @@ -10,7 +10,7 @@ MKDUMPRD="/sbin/mkdumprd -f" MKFADUMPRD="/sbin/mkfadumprd" DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" SAVE_PATH=/var/crash -SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" +SSH_KEY_LOCATION=$DEFAULT_SSHKEY INITRD_CHECKSUM_LOCATION="/boot/.fadump_initrd_checksum" DUMP_TARGET="" DEFAULT_INITRD="" diff --git a/mkdumprd b/mkdumprd index 5996d50..3e250e0 100644 --- a/mkdumprd +++ b/mkdumprd @@ -22,7 +22,7 @@ if ! dlog_init; then exit 1 fi -SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa" +SSH_KEY_LOCATION=$DEFAULT_SSHKEY SAVE_PATH=$(get_save_path) OVERRIDE_RESETTABLE=0 From 247b3dd297f1ee2224af2d3b838019af428c387e Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:02 +0100 Subject: [PATCH 210/454] kdumpctl: fix comment in check_and_wait_network_ready The time out was increased to 180 seconds in 680c0d3 ("kdumpctl: distinguish the failed reason of ssh"). Update the comment to reflect that change. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 7b01cd3..7d40f76 100755 --- a/kdumpctl +++ b/kdumpctl @@ -734,7 +734,7 @@ check_and_wait_network_ready() cur=$(date +%s) diff=$((cur - start_time)) - # 60s time out + # time out after 180s if [[ $diff -gt 180 ]]; then break fi From b802dbff9f0da8b5cd6eebf28dd3e7fd207cc45c Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:03 +0100 Subject: [PATCH 211/454] kdumpctl: forbid aliases from ssh config For ssh targets kdumpctl only verifies that the config value has the correct @ format itself. For all other tests, e.g. if the destination can be reached, it relies on ssh. This allows users to provide a that isn't the proper hostname but an alias defined in the ssh_config without failing the tests. If this is done dracut-module-setup.sh:kdump_get_remote_ip will fail to obtain the targets ip address. This failure is not detected and thus will not fail the initramfs creation. The resulting initramfs however doesn't have the necessary information for setting up the network and thus will fail to boot. Prevent the use of alias hostnames by verifying that the given hostname is the same one ssh would use after parsing the ssh_config. Note: Don't use getent ahosts to verify that the given host can be resolved as this requires the network to be up which cannot be guaranteed when the kdump.conf is parsed. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kdumpctl b/kdumpctl index 7d40f76..8ad6e4c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -663,7 +663,7 @@ load_kdump() check_ssh_config() { - local SSH_TARGET + local target while read -r config_opt config_val; do case "$config_opt" in @@ -687,11 +687,14 @@ check_ssh_config() esac done <<< "$(kdump_read_conf)" - #make sure they've configured kdump.conf for ssh dumps - SSH_TARGET=$(echo -n "$DUMP_TARGET" | sed -n '/.*@/p') - if [[ -z $SSH_TARGET ]]; then + [[ -n $DUMP_TARGET ]] || return 1 + [[ $DUMP_TARGET =~ .*@.* ]] || return 1 + target=$(ssh -G "$DUMP_TARGET" | sed -n -e "s/^hostname[[:space:]]\+\([^[:space:]]*\).*$/\1/p") + if [[ ${DUMP_TARGET#*@} != "$target" ]]; then + derror "Invalid ssh destination $DUMP_TARGET provided." return 1 fi + return 0 } From e3fa3678404e161be27914b91c69693613b1fcfe Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:04 +0100 Subject: [PATCH 212/454] kdumpctl: simplify propagate_ssh_key The function has multiple problems: 1) SSH_{USER,SERVER} aren't defined local 2) Weird use of cut and sed to parse the DUMP_TARGET for the user and host although check_ssh_config guarantees that it has the format @. 3) Unnecessary use of a variable for the return value 4) Weird behavior to first unpack the DUMP_TARGET to SSH_USER and SSH_SERVER and then putting it back together again 5) Definition of variable errmsg that is only used once but breaks grep-ability of error message. 6) Wrong order when redirecting output of ssh-keygen, see SC2069 [1] Fix them now. While at it also improve the error messages in the function. [1] https://www.shellcheck.net/wiki/SC2069 Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/kdumpctl b/kdumpctl index 8ad6e4c..e6d5066 100755 --- a/kdumpctl +++ b/kdumpctl @@ -755,35 +755,32 @@ check_ssh_target() propagate_ssh_key() { + local SSH_USER SSH_SERVER + if ! check_ssh_config; then - derror "No ssh config specified in $KDUMP_CONFIG_FILE. Can't propagate" + derror "No ssh destination defined in $KDUMP_CONFIG_FILE." + derror "Please verify that $KDUMP_CONFIG_FILE contains 'ssh @' and that it is properly formatted." exit 1 fi local KEYFILE=$SSH_KEY_LOCATION - local errmsg="Failed to propagate ssh key" #Check to see if we already created key, if not, create it. if [[ -f $KEYFILE ]]; then dinfo "Using existing keys..." else dinfo "Generating new ssh keys... " - /usr/bin/ssh-keygen -t rsa -f "$KEYFILE" -N "" 2>&1 > /dev/null + /usr/bin/ssh-keygen -t rsa -f "$KEYFILE" -N "" &> /dev/null dinfo "done." fi - #now find the target ssh user and server to contact. - SSH_USER=$(echo "$DUMP_TARGET" | cut -d@ -f1) - SSH_SERVER=$(echo "$DUMP_TARGET" | sed -e's/\(.*@\)\(.*$\)/\2/') - - #now send the found key to the found server - ssh-copy-id -i "$KEYFILE" "$SSH_USER@$SSH_SERVER" - RET=$? - if [[ $RET == 0 ]]; then + SSH_USER=${DUMP_TARGET%@*} + SSH_SERVER=${DUMP_TARGET#*@} + if ssh-copy-id -i "$KEYFILE" "$DUMP_TARGET"; then dinfo "$KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER" return 0 else - derror "$errmsg, $KEYFILE failed in transfer to $SSH_SERVER" + derror "Failed to propagate ssh key, could not transfer $KEYFILE to $SSH_SERVER" exit 1 fi } From 4adf6d3cc85811d47ddc90c89a6f47b699350410 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:05 +0100 Subject: [PATCH 213/454] kdumpctl: merge check_ssh_config into check_config check_config and check_ssh_config both parse /etc/kdump.conf and are usually used together. The difference between both is that check_ssh_config does some extra checks on the format of the provided ssh destination but ignores invalid or deprecated options in the config. Thus merge check_ssh_config into check_config. Leave the additional checks on the ssh destination in check_ssh_config but treat it like the checks done for e.g. the failure_action. This slightly changes the behavior of 'kdumpctl propagate', which now fails if kdump.conf contains an invalid value unrelated to ssh. This change in behavior isn't problematic because 'kdumpctl propagate' always needs to be followed by a 'kdumpctl start' to have a working kdump environment. For the situations where 'propagate' fails now the 'start' would have failed in the past. So the failure only moved one step ahead in the sequence. While at it drop check_ssh_target and call check_and_wait_network_ready directly. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 71 ++++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/kdumpctl b/kdumpctl index e6d5066..85ea7aa 100755 --- a/kdumpctl +++ b/kdumpctl @@ -205,10 +205,27 @@ check_config() fi config_opt=_target ;; - ext[234] | minix | btrfs | xfs | nfs | ssh) + ext[234] | minix | btrfs | xfs | nfs ) config_opt=_target ;; - sshkey | path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; + ssh) + config_opt=_target + DUMP_TARGET=$config_val + ;; + sshkey) + if [[ -z $config_val ]]; then + derror "Invalid kdump config value for option '$config_opt'" + return 1 + elif [[ -f $config_val ]]; then + SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val") + else + dwarn "WARNING: '$config_val' doesn't exist, using default value '$SSH_KEY_LOCATION'" + fi + ;; + path) + SAVE_PATH=$config_val + ;; + core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; net | options | link_delay | disk_timeout | debug_mem_level | blacklist) derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." @@ -242,6 +259,7 @@ check_config() check_failure_action_config || return 1 check_final_action_config || return 1 check_fence_kdump_config || return 1 + check_ssh_config || return 1 return 0 } @@ -665,29 +683,8 @@ check_ssh_config() { local target - while read -r config_opt config_val; do - case "$config_opt" in - sshkey) - # remove inline comments after the end of a directive. - if [[ -f $config_val ]]; then - # canonicalize the path - SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val") - else - dwarn "WARNING: '$config_val' doesn't exist, using default value '$SSH_KEY_LOCATION'" - fi - ;; - path) - SAVE_PATH=$config_val - ;; - ssh) - DUMP_TARGET=$config_val - ;; - *) ;; + [[ -n $DUMP_TARGET ]] || return 0 - esac - done <<< "$(kdump_read_conf)" - - [[ -n $DUMP_TARGET ]] || return 1 [[ $DUMP_TARGET =~ .*@.* ]] || return 1 target=$(ssh -G "$DUMP_TARGET" | sed -n -e "s/^hostname[[:space:]]\+\([^[:space:]]*\).*$/\1/p") if [[ ${DUMP_TARGET#*@} != "$target" ]]; then @@ -710,6 +707,8 @@ check_and_wait_network_ready() local retval local errmsg + [[ -n $DUMP_TARGET ]] || return 0 + start_time=$(date +%s) while true; do errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1) @@ -748,16 +747,13 @@ check_and_wait_network_ready() return 1 } -check_ssh_target() -{ - check_and_wait_network_ready -} - propagate_ssh_key() { local SSH_USER SSH_SERVER - if ! check_ssh_config; then + check_config || return 1 + + if [[ -z $DUMP_TARGET ]] ; then derror "No ssh destination defined in $KDUMP_CONFIG_FILE." derror "Please verify that $KDUMP_CONFIG_FILE contains 'ssh @' and that it is properly formatted." exit 1 @@ -1040,11 +1036,9 @@ start() return 0 fi - if check_ssh_config; then - if ! check_ssh_target; then - derror "Starting kdump: [FAILED]" - return 1 - fi + if ! check_and_wait_network_ready; then + derror "Starting kdump: [FAILED]" + return 1 fi if ! check_rebuild; then @@ -1160,12 +1154,7 @@ stop() rebuild() { check_config || return 1 - - if check_ssh_config; then - if ! check_ssh_target; then - return 1 - fi - fi + check_and_wait_network_ready || return 1 setup_initrd || return 1 From edb1d04425605db53637f698422017b609efe2b4 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:06 +0100 Subject: [PATCH 214/454] kdumpctl: reduce file operations on kdump.conf Every call to kdump_get_conf_val parses kdump.conf although the file has already been parsed in check_config. Thus store the values parsed in check_config in an array and use them later instead of re-parsing the file over and over again. While at it rename check_config to parse_config. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 73 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/kdumpctl b/kdumpctl index 85ea7aa..0b57384 100755 --- a/kdumpctl +++ b/kdumpctl @@ -27,6 +27,8 @@ standard_kexec_args="-d -p" # Some default values in case /etc/sysconfig/kdump doesn't include KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug" +declare -A OPT + if [[ -f /etc/sysconfig/kdump ]]; then . /etc/sysconfig/kdump fi @@ -185,9 +187,29 @@ restore_default_initrd() fi } -check_config() +_set_config() +{ + local opt=$1 + local val=$2 + + if [[ -z $val ]]; then + derror "Invalid kdump config value for option '$opt'" + return 1 + fi + + if [[ -n ${OPT[$opt]} ]]; then + if [[ $opt == _target ]]; then + derror "More than one dump targets specified" + else + derror "Duplicated kdump config value of option $opt" + fi + return 1 + fi + OPT[$opt]="$val" +} + +parse_config() { - local -A _opt_rec while read -r config_opt config_val; do case "$config_opt" in dracut_args) @@ -196,7 +218,7 @@ check_config() derror 'Multiple mount targets specified in one "dracut_args".' return 1 fi - config_opt=_target + _set_config _target "$(get_dracut_args_target "$config_val")" || return 1 fi ;; raw) @@ -240,20 +262,7 @@ check_config() ;; esac - if [[ -z $config_val ]]; then - derror "Invalid kdump config value for option '$config_opt'" - return 1 - fi - - if [[ -n ${_opt_rec[$config_opt]} ]]; then - if [[ $config_opt == _target ]]; then - derror "More than one dump targets specified" - else - derror "Duplicated kdump config value of option $config_opt" - fi - return 1 - fi - _opt_rec[$config_opt]="$config_val" + _set_config "$config_opt" "$config_val" || return 1 done <<< "$(kdump_read_conf)" check_failure_action_config || return 1 @@ -321,8 +330,8 @@ check_files_modified() #also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. modified_files=$(get_pcs_cluster_modified_files) - EXTRA_BINS=$(kdump_get_conf_val kdump_post) - CHECK_FILES=$(kdump_get_conf_val kdump_pre) + EXTRA_BINS=${OPT[kdump_post]} + CHECK_FILES=${OPT[kdump_pre]} HOOKS="/etc/kdump/post.d/ /etc/kdump/pre.d/" if [[ -d /etc/kdump/post.d ]]; then for file in /etc/kdump/post.d/*; do @@ -339,17 +348,17 @@ check_files_modified() done fi HOOKS="$HOOKS $POST_FILES $PRE_FILES" - CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}') + CORE_COLLECTOR=$(echo "${OPT[core_collector]}" | awk '{print $1}') CORE_COLLECTOR=$(type -P "$CORE_COLLECTOR") # POST_FILES and PRE_FILES are already checked against executable, need not to check again. EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" - CHECK_FILES=$(kdump_get_conf_val extra_bins) + CHECK_FILES=${OPT[extra_bins]} EXTRA_BINS="$EXTRA_BINS $CHECK_FILES" files="$KDUMP_CONFIG_FILE $KDUMP_KERNEL $EXTRA_BINS $CORE_COLLECTOR" [[ -e /etc/fstab ]] && files="$files /etc/fstab" # Check for any updated extra module - EXTRA_MODULES="$(kdump_get_conf_val extra_modules)" + EXTRA_MODULES="${OPT[extra_modules]}" if [[ -n $EXTRA_MODULES ]]; then if [[ -e /lib/modules/$KDUMP_KERNELVER/modules.dep ]]; then files="$files /lib/modules/$KDUMP_KERNELVER/modules.dep" @@ -541,14 +550,14 @@ check_rebuild() setup_initrd || return 1 - force_no_rebuild=$(kdump_get_conf_val force_no_rebuild) + force_no_rebuild=${OPT[force_no_rebuild]} force_no_rebuild=${force_no_rebuild:-0} if [[ $force_no_rebuild != "0" ]] && [[ $force_no_rebuild != "1" ]]; then derror "Error: force_no_rebuild value is invalid" return 1 fi - force_rebuild=$(kdump_get_conf_val force_rebuild) + force_rebuild=${OPT[force_rebuild]} force_rebuild=${force_rebuild:-0} if [[ $force_rebuild != "0" ]] && [[ $force_rebuild != "1" ]]; then derror "Error: force_rebuild value is invalid" @@ -751,7 +760,7 @@ propagate_ssh_key() { local SSH_USER SSH_SERVER - check_config || return 1 + parse_config || return 1 if [[ -z $DUMP_TARGET ]] ; then derror "No ssh destination defined in $KDUMP_CONFIG_FILE." @@ -825,7 +834,7 @@ save_raw() dwarn "Warning: Detected '$check_fs' signature on $raw_target, data loss is expected." return 0 fi - kdump_dir=$(kdump_get_conf_val path) + kdump_dir=${OPT[path]} if [[ -z ${kdump_dir} ]]; then coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" else @@ -911,7 +920,7 @@ check_fence_kdump_config() hostname=$(hostname) ipaddrs=$(hostname -I) - nodes=$(kdump_get_conf_val "fence_kdump_nodes") + nodes=${OPT[fence_kdump_nodes]} for node in $nodes; do if [[ $node == "$hostname" ]]; then @@ -964,8 +973,8 @@ check_failure_action_config() local failure_action local option="failure_action" - default_option=$(kdump_get_conf_val default) - failure_action=$(kdump_get_conf_val failure_action) + default_option=${OPT[default]} + failure_action=${OPT[failure_action]} if [[ -z $failure_action ]] && [[ -z $default_option ]]; then return 0 @@ -994,7 +1003,7 @@ check_final_action_config() { local final_action - final_action=$(kdump_get_conf_val final_action) + final_action=${OPT[final_action]} if [[ -z $final_action ]]; then return 0 else @@ -1017,7 +1026,7 @@ start() return 1 fi - if ! check_config; then + if ! parse_config; then derror "Starting kdump: [FAILED]" return 1 fi @@ -1153,7 +1162,7 @@ stop() rebuild() { - check_config || return 1 + parse_config || return 1 check_and_wait_network_ready || return 1 setup_initrd || return 1 From 0460f0a7686334a14c5b17ef00721ad25c54324b Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:07 +0100 Subject: [PATCH 215/454] kdumpctl: drop SAVE_PATH variable The variable is only used for ssh dump targets. Furthermore it is identical to the value stored in ${OPT[path]}. Thus drop SAVE_PATH and use ${OPT[path]} instead. Also make sure that ${OPT[path]} is always set to the default value when no entry in kdump.conf is found. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/kdumpctl b/kdumpctl index 0b57384..876561e 100755 --- a/kdumpctl +++ b/kdumpctl @@ -9,7 +9,6 @@ KDUMP_LOG_PATH="/var/log" MKDUMPRD="/sbin/mkdumprd -f" MKFADUMPRD="/sbin/mkfadumprd" DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" -SAVE_PATH=/var/crash SSH_KEY_LOCATION=$DEFAULT_SSHKEY INITRD_CHECKSUM_LOCATION="/boot/.fadump_initrd_checksum" DUMP_TARGET="" @@ -244,10 +243,7 @@ parse_config() dwarn "WARNING: '$config_val' doesn't exist, using default value '$SSH_KEY_LOCATION'" fi ;; - path) - SAVE_PATH=$config_val - ;; - core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; + path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; net | options | link_delay | disk_timeout | debug_mem_level | blacklist) derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." @@ -265,6 +261,8 @@ parse_config() _set_config "$config_opt" "$config_val" || return 1 done <<< "$(kdump_read_conf)" + OPT[path]=${OPT[path]:-$DEFAULT_PATH} + check_failure_action_config || return 1 check_final_action_config || return 1 check_fence_kdump_config || return 1 @@ -720,21 +718,21 @@ check_and_wait_network_ready() start_time=$(date +%s) while true; do - errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "$SAVE_PATH" 2>&1) + errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "${OPT[path]}" 2>&1) retval=$? # ssh exits with the exit status of the remote command or with 255 if an error occurred if [[ $retval -eq 0 ]]; then return 0 elif [[ $retval -ne 255 ]]; then - derror "Could not create $DUMP_TARGET:$SAVE_PATH, you should check the privilege on server side" + derror "Could not create $DUMP_TARGET:${OPT[path]}, you should check the privilege on server side" return 1 fi # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa ddebug "$errmsg" if echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed"; then - derror "Could not create $DUMP_TARGET:$SAVE_PATH, you probably need to run \"kdumpctl propagate\"" + derror "Could not create $DUMP_TARGET:${OPT[path]}, you probably need to run \"kdumpctl propagate\"" return 1 fi @@ -752,7 +750,7 @@ check_and_wait_network_ready() sleep 1 done - dinfo "Could not create $DUMP_TARGET:$SAVE_PATH, ipaddr is not ready yet. You should check network connection" + dinfo "Could not create $DUMP_TARGET:${OPT[path]}, ipaddr is not ready yet. You should check network connection" return 1 } @@ -820,7 +818,6 @@ check_current_status() save_raw() { - local kdump_dir local raw_target raw_target=$(kdump_get_conf_val raw) @@ -834,13 +831,8 @@ save_raw() dwarn "Warning: Detected '$check_fs' signature on $raw_target, data loss is expected." return 0 fi - kdump_dir=${OPT[path]} - if [[ -z ${kdump_dir} ]]; then - coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")" - else - coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")" - fi + coredir="${OPT[path]}/$(date +"%Y-%m-%d-%H:%M")" mkdir -p "$coredir" [[ -d $coredir ]] || { derror "failed to create $coredir" From a859abe3652c1eea75b847e6f6f93033b478a4d3 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:08 +0100 Subject: [PATCH 216/454] kdumpctl: drop SSH_KEY_LOCATION variable The variable is only used for ssh dump targets. Furthermore it is identical to the value stored in ${OPT[sshkey]}. Thus drop SSH_KEY_LOCATION and use ${OPT[sshkey]} instead. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kdumpctl b/kdumpctl index 876561e..c5afedb 100755 --- a/kdumpctl +++ b/kdumpctl @@ -9,7 +9,6 @@ KDUMP_LOG_PATH="/var/log" MKDUMPRD="/sbin/mkdumprd -f" MKFADUMPRD="/sbin/mkfadumprd" DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" -SSH_KEY_LOCATION=$DEFAULT_SSHKEY INITRD_CHECKSUM_LOCATION="/boot/.fadump_initrd_checksum" DUMP_TARGET="" DEFAULT_INITRD="" @@ -238,9 +237,10 @@ parse_config() derror "Invalid kdump config value for option '$config_opt'" return 1 elif [[ -f $config_val ]]; then - SSH_KEY_LOCATION=$(/usr/bin/readlink -m "$config_val") + config_val=$(/usr/bin/readlink -m "$config_val") else - dwarn "WARNING: '$config_val' doesn't exist, using default value '$SSH_KEY_LOCATION'" + dwarn "WARNING: '$config_val' doesn't exist, using default value '$DEFAULT_SSHKEY'" + config_val=$DEFAULT_SSHKEY fi ;; path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; @@ -262,6 +262,7 @@ parse_config() done <<< "$(kdump_read_conf)" OPT[path]=${OPT[path]:-$DEFAULT_PATH} + OPT[sshkey]=${OPT[sshkey]:-$DEFAULT_SSHKEY} check_failure_action_config || return 1 check_final_action_config || return 1 @@ -718,7 +719,7 @@ check_and_wait_network_ready() start_time=$(date +%s) while true; do - errmsg=$(ssh -i "$SSH_KEY_LOCATION" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "${OPT[path]}" 2>&1) + errmsg=$(ssh -i "${OPT[sshkey]}" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "${OPT[path]}" 2>&1) retval=$? # ssh exits with the exit status of the remote command or with 255 if an error occurred @@ -766,7 +767,7 @@ propagate_ssh_key() exit 1 fi - local KEYFILE=$SSH_KEY_LOCATION + local KEYFILE=${OPT[sshkey]} #Check to see if we already created key, if not, create it. if [[ -f $KEYFILE ]]; then From 5118daf2ff9f2283782ea38e4b99cf9c307c2324 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:09 +0100 Subject: [PATCH 217/454] kdumpctl: drop DUMP_TARGET variable The variable is only used for ssh dump targets. Furthermore it is identical to the value stored in ${OPT[_target]}. Thus drop DUMP_TARGET and use ${OPT[_target]} instead. In order to be able to distinguish between the different target types introduce the internal ${OPT[_fstype]}. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/kdumpctl b/kdumpctl index c5afedb..bfba442 100755 --- a/kdumpctl +++ b/kdumpctl @@ -10,7 +10,6 @@ MKDUMPRD="/sbin/mkdumprd -f" MKFADUMPRD="/sbin/mkfadumprd" DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" INITRD_CHECKSUM_LOCATION="/boot/.fadump_initrd_checksum" -DUMP_TARGET="" DEFAULT_INITRD="" DEFAULT_INITRD_BAK="" KDUMP_INITRD="" @@ -196,7 +195,7 @@ _set_config() fi if [[ -n ${OPT[$opt]} ]]; then - if [[ $opt == _target ]]; then + if [[ $opt == _target ]] || [[ $opt == _fstype ]]; then derror "More than one dump targets specified" else derror "Duplicated kdump config value of option $opt" @@ -216,6 +215,7 @@ parse_config() derror 'Multiple mount targets specified in one "dracut_args".' return 1 fi + _set_config _fstype "$(get_dracut_args_fstype "$config_val")" || return 1 _set_config _target "$(get_dracut_args_target "$config_val")" || return 1 fi ;; @@ -223,15 +223,13 @@ parse_config() if [[ -d "/proc/device-tree/ibm,opal/dump" ]]; then dwarn "WARNING: Won't capture opalcore when 'raw' dump target is used." fi + _set_config _fstype "$config_opt" || return 1 config_opt=_target ;; - ext[234] | minix | btrfs | xfs | nfs ) + ext[234] | minix | btrfs | xfs | nfs | ssh) + _set_config _fstype "$config_opt" || return 1 config_opt=_target ;; - ssh) - config_opt=_target - DUMP_TARGET=$config_val - ;; sshkey) if [[ -z $config_val ]]; then derror "Invalid kdump config value for option '$config_opt'" @@ -691,12 +689,12 @@ check_ssh_config() { local target - [[ -n $DUMP_TARGET ]] || return 0 + [[ "${OPT[_fstype]}" == ssh ]] || return 0 - [[ $DUMP_TARGET =~ .*@.* ]] || return 1 - target=$(ssh -G "$DUMP_TARGET" | sed -n -e "s/^hostname[[:space:]]\+\([^[:space:]]*\).*$/\1/p") - if [[ ${DUMP_TARGET#*@} != "$target" ]]; then - derror "Invalid ssh destination $DUMP_TARGET provided." + target=$(ssh -G "${OPT[_target]}" | sed -n -e "s/^hostname[[:space:]]\+\([^[:space:]]*\).*$/\1/p") + [[ ${OPT[_target]} =~ .*@.* ]] || return 1 + if [[ ${OPT[_target]#*@} != "$target" ]]; then + derror "Invalid ssh destination ${OPT[_target]} provided." return 1 fi @@ -715,25 +713,25 @@ check_and_wait_network_ready() local retval local errmsg - [[ -n $DUMP_TARGET ]] || return 0 + [[ "${OPT[_fstype]}" == ssh ]] || return 0 start_time=$(date +%s) while true; do - errmsg=$(ssh -i "${OPT[sshkey]}" -o BatchMode=yes "$DUMP_TARGET" mkdir -p "${OPT[path]}" 2>&1) + errmsg=$(ssh -i "${OPT[sshkey]}" -o BatchMode=yes "${OPT[_target]}" mkdir -p "${OPT[path]}" 2>&1) retval=$? # ssh exits with the exit status of the remote command or with 255 if an error occurred if [[ $retval -eq 0 ]]; then return 0 elif [[ $retval -ne 255 ]]; then - derror "Could not create $DUMP_TARGET:${OPT[path]}, you should check the privilege on server side" + derror "Could not create ${OPT[_target]}:${OPT[path]}, you should check the privilege on server side" return 1 fi # if server removes the authorized_keys or, no /root/.ssh/kdump_id_rsa ddebug "$errmsg" if echo "$errmsg" | grep -q "Permission denied\|No such file or directory\|Host key verification failed"; then - derror "Could not create $DUMP_TARGET:${OPT[path]}, you probably need to run \"kdumpctl propagate\"" + derror "Could not create ${OPT[_target]}:${OPT[path]}, you probably need to run \"kdumpctl propagate\"" return 1 fi @@ -751,7 +749,7 @@ check_and_wait_network_ready() sleep 1 done - dinfo "Could not create $DUMP_TARGET:${OPT[path]}, ipaddr is not ready yet. You should check network connection" + dinfo "Could not create ${OPT[_target]}:${OPT[path]}, ipaddr is not ready yet. You should check network connection" return 1 } @@ -761,7 +759,7 @@ propagate_ssh_key() parse_config || return 1 - if [[ -z $DUMP_TARGET ]] ; then + if [[ ${OPT[_fstype]} != ssh ]] ; then derror "No ssh destination defined in $KDUMP_CONFIG_FILE." derror "Please verify that $KDUMP_CONFIG_FILE contains 'ssh @' and that it is properly formatted." exit 1 @@ -778,9 +776,9 @@ propagate_ssh_key() dinfo "done." fi - SSH_USER=${DUMP_TARGET%@*} - SSH_SERVER=${DUMP_TARGET#*@} - if ssh-copy-id -i "$KEYFILE" "$DUMP_TARGET"; then + SSH_USER=${OPT[_target]%@*} + SSH_SERVER=${OPT[_target]#*@} + if ssh-copy-id -i "$KEYFILE" "${OPT[_target]}"; then dinfo "$KEYFILE has been added to ~$SSH_USER/.ssh/authorized_keys on $SSH_SERVER" return 0 else From ac5968218f4d4d86d5ad217c0912a81e985c5893 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:10 +0100 Subject: [PATCH 218/454] kdumpctl: remove kdump_get_conf_val in save_raw With the introduction of ${OPT[fstype]} this call to kdump_get_conf_val can be removed now as well. Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index bfba442..82e8574 100755 --- a/kdumpctl +++ b/kdumpctl @@ -819,8 +819,9 @@ save_raw() { local raw_target - raw_target=$(kdump_get_conf_val raw) - [[ -z $raw_target ]] && return 0 + [[ ${OPT[_fstype]} == raw ]] || return 0 + + raw_target=${OPT[_target]} [[ -b $raw_target ]] || { derror "raw partition $raw_target not found" return 1 From 55b5c4e2b0105ae5b64ab3a5ea1c1879dc818a03 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 25 Mar 2022 15:47:11 +0100 Subject: [PATCH 219/454] kdumpctl: simplify local_fs_dump_target Make use of the new ${OPT[]} array and simplify local_fs_dump_target to remove one more file operations. While at it rename the local_fs_dump_target to is_local_target Signed-off-by: Philipp Rudo Reviewed-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kdumpctl b/kdumpctl index 82e8574..4d819c2 100755 --- a/kdumpctl +++ b/kdumpctl @@ -850,27 +850,22 @@ save_raw() return 0 } -local_fs_dump_target() +is_local_target() { - local _target - - if _target=$(grep -E "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf); then - echo "$_target" | awk '{print $2}' - fi + [[ ${OPT[_fstype]} =~ ^ext[234]|^xfs|^btrfs|^minix ]] } path_to_be_relabeled() { - local _path _target _mnt="/" _rmnt + local _path _mnt="/" _rmnt if is_user_configured_dump_target; then if is_mount_in_dracut_args; then return fi - _target=$(local_fs_dump_target) - if [[ -n $_target ]]; then - _mnt=$(get_mntpoint_from_target "$_target") + if is_local_target; then + _mnt=$(get_mntpoint_from_target "${OPT[_target]}") if ! is_mounted "$_mnt"; then return fi From 11140c28a25169837333c5bf7d51cbe17c897025 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 11 Apr 2022 10:56:46 +0800 Subject: [PATCH 220/454] Release 2.0.24-1 --- kexec-tools.spec | 28 ++++++++++++++++++++++++---- sources | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 6b7ef14..db6374c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,8 +4,8 @@ %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools -Version: 2.0.23 -Release: 5%{?dist} +Version: 2.0.24 +Release: 1%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -103,7 +103,6 @@ Requires: systemd-udev%{?_isa} # # Patches 401 through 500 are meant for s390 kexec-tools enablement # -Patch401: ./kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch # # Patches 501 through 600 are meant for ARM kexec-tools enablement @@ -127,7 +126,6 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} -%patch401 -p1 %ifarch ppc %define archdef ARCH=ppc @@ -407,6 +405,28 @@ fi %endif %changelog +* Mon Apr 11 2022 Coiby - 2.0.24-1 +- Update kexec-tools to 2.0.24 +- kdumpctl: remove kdump_get_conf_val in save_raw +- kdumpctl: drop DUMP_TARGET variable +- kdumpctl: drop SSH_KEY_LOCATION variable +- kdumpctl: drop SAVE_PATH variable +- kdumpctl: reduce file operations on kdump.conf +- kdumpctl: merge check_ssh_config into check_config +- kdumpctl: simplify propagate_ssh_key +- kdumpctl: forbid aliases from ssh config +- kdumpctl: fix comment in check_and_wait_network_ready +- kdump-lib-initramfs: merge definitions for default ssh key +- kdumpctl: remove unnecessary uses of $? +- kdump-lib: fix typo in variable name +- kdump-capture.service: switch to journal for stdout +- kdumpctl/estimate: Fix unnecessary warning +- kdumpctl: sync the $TARGET_INITRD after rebuild +- try to update the crashkernel in GRUB_ETC_DEFAULT after kexec-tools updates the default crashkernel value +- address the case where there are multiple values for the same kernel arg +- update kernel crashkernel in posttrans RPM scriptlet when updating kexec-tools +- kdump-lib.sh: Check the output of blkid with sed instead of eval + * Mon Feb 14 2022 Coiby - 2.0.23-5 - fix incorrect usage of _get_all_kernels_from_grubby - fix the mistake of swapping function parameters of read_proc_environ_var diff --git a/sources b/sources index 5069108..95c0fc6 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 -SHA512 (kexec-tools-2.0.23.tar.xz) = b6e3b967cacc31c434b185d25da4d53c822ae4bbcec26ef9d6cb171f294fdcc80913d381e686a0a41e025187835f4dc088052ff88efe75a021d7624c8b1a1ed8 +SHA512 (kexec-tools-2.0.24.tar.xz) = ef7cf78246e2d729d81a3649791a5a23c385353cc75cbe8ef279616329fdaccc876d614c7f51e1456822a13a11520296070d9897467d24310399909e049c3822 SHA512 (makedumpfile-1.7.0.tar.gz) = 579a1fb79d023a1419fc8612a02a04dda3e3b3d72455566433ab6bec08627aa9a176c55566393a081a7aae3fd0543800196596b25445b21b16346556723e9cf7 From b97310428f336d58028d34f3f3c7a551e47b5c32 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 4 Jan 2022 14:04:38 +0800 Subject: [PATCH 221/454] unit tests: prepare for kdumpctl and kdump-lib.sh to be unit-tested Currently there are two issues with unit-testing the functions defined in kdumpctl and other shell scripts after sourcing them, - kdumpctl would call main which requires root permission and would create single instance lock (/var/lock/kdump) - kdumpctl and other shell scripts directly source files under /usr/lib/kdump/ When ShellSpec load a script via "Include", it defines the__SOURCED__ variable. By making use of __SOURCED__, we can 1. let kdumpctl not call main when kdumpctl is "Include"d by ShellSpec 2. instruct kdumpctl and kdump-lib.sh to source the files in the repo when running ShelSpec tests Note coverage/ is added to .gitignore because ShellSpec generates code coverage results in this folder. Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- .gitignore | 1 + kdump-lib.sh | 7 +++++-- kdumpctl | 24 +++++++++++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 7a38a39..e9c2dd8 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ /kexec-tools-2.0.11.tar.xz /makedumpfile-1.5.9.tar.gz /kexec-tools-2.0.12.tar.xz +coverage/ diff --git a/kdump-lib.sh b/kdump-lib.sh index 5b1656e..557eff6 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -2,8 +2,11 @@ # # Kdump common variables and functions # - -. /usr/lib/kdump/kdump-lib-initramfs.sh +if [[ ${__SOURCED__:+x} ]]; then + . ./kdump-lib-initramfs.sh +else + . /lib/kdump/kdump-lib-initramfs.sh +fi FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" diff --git a/kdumpctl b/kdumpctl index 4d819c2..6188d47 100755 --- a/kdumpctl +++ b/kdumpctl @@ -32,8 +32,14 @@ fi [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut . $dracutbasedir/dracut-functions.sh -. /lib/kdump/kdump-lib.sh -. /lib/kdump/kdump-logger.sh + +if [[ ${__SOURCED__:+x} ]]; then + KDUMP_LIB_PATH=. +else + KDUMP_LIB_PATH=/lib/kdump +fi +. $KDUMP_LIB_PATH/kdump-lib.sh +. $KDUMP_LIB_PATH/kdump-logger.sh #initiate the kdump logger if ! dlog_init; then @@ -1676,11 +1682,6 @@ reset_crashkernel_for_installed_kernel() fi } -if [[ ! -f $KDUMP_CONFIG_FILE ]]; then - derror "Error: No kdump config file found!" - exit 1 -fi - main() { # Determine if the dump mode is kdump or fadump @@ -1753,6 +1754,15 @@ main() esac } +if [[ ${__SOURCED__:+x} ]]; then + return +fi + +if [[ ! -f $KDUMP_CONFIG_FILE ]]; then + derror "Error: No kdump config file found!" + exit 1 +fi + # Other kdumpctl instances will block in queue, until this one exits single_instance_lock From 93373c040627f31826d864110413c4e1f72e9b4b Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 5 Jan 2022 13:48:58 +0800 Subject: [PATCH 222/454] unit tests: add tests for get_grub_kernel_boot_parameter This test suite makes use of three features provided by ShellSpec - funcion-based mock [2]: mock a function by re-defining and exporting it - parameterized tests [3]: run multiple sets of input against the same test - %text directive [4]: similar to heredoc but free of the indentation issue Note 1. Describe and Context are aliases for ExampleGroup which a block for grouping example groups or examples [5]. Describe and Context are used to improve readability. 2. ShellSpec requires .shellspec file. [1] https://github.com/dodie/testing-in-bash#detailed-comparision [2] https://github.com/shellspec/shellspec#function-based-mock [3] https://github.com/shellspec/shellspec#parameters---parameterized-example [4] https://github.com/shellspec/shellspec#text---embedded-text [5] https://github.com/shellspec/shellspec#dsl-syntax Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- .shellspec | 0 spec/kdumpctl_general_spec.sh | 48 +++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .shellspec create mode 100644 spec/kdumpctl_general_spec.sh diff --git a/.shellspec b/.shellspec new file mode 100644 index 0000000..e69de29 diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh new file mode 100644 index 0000000..e1d8698 --- /dev/null +++ b/spec/kdumpctl_general_spec.sh @@ -0,0 +1,48 @@ +#!/bin/bash +Describe 'kdumpctl' + Include ./kdumpctl + + Describe 'get_grub_kernel_boot_parameter()' + grubby() { + %text + #|index=1 + #|kernel="/boot/vmlinuz-5.14.14-200.fc34.x86_64" + #|args="crashkernel=11M nvidia-drm.modeset=1 crashkernel=100M ro rhgb quiet crcrashkernel=200M crashkernel=32T-64T:128G,64T-102400T:180G fadump=on" + #|root="UUID=45fdf703-3966-401b-b8f7-cf056affd2b0" + } + DUMMY_PARAM=/boot/vmlinuz + + Context "when given a kernel parameter in different positions" + # Test the following cases: + # - the kernel parameter in the end + # - the kernel parameter in the first + # - the kernel parameter is crashkernel (suffix of crcrashkernel) + # - the kernel parameter that does not exist + # - the kernel parameter doesn't have a value + Parameters + # parameter answer + fadump on + nvidia-drm.modeset 1 + crashkernel 32T-64T:128G,64T-102400T:180G + aaaa "" + ro "" + End + + It 'should retrieve the value succesfully' + When call get_grub_kernel_boot_parameter "$DUMMY_PARAM" "$2" + The output should equal "$3" + End + End + + It 'should retrive the last value if multiple entries exist' + When call get_grub_kernel_boot_parameter "$DUMMY_PARAM" crashkernel + The output should equal '32T-64T:128G,64T-102400T:180G' + End + + It 'should fail when called with kernel_path=ALL' + When call get_grub_kernel_boot_parameter ALL ro + The status should be failure + The error should include "kernel_path=ALL invalid" + End + End +End From 59386d5a8b1d2c2c2f9e8cdeb2a9e17565316033 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 5 Jan 2022 15:24:02 +0800 Subject: [PATCH 223/454] unit tests: add tests for get_dump_mode_by_fadump_val Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_general_spec.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index e1d8698..b968f74 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -45,4 +45,30 @@ Describe 'kdumpctl' The error should include "kernel_path=ALL invalid" End End + + Describe 'get_dump_mode_by_fadump_val()' + + Context 'when given valid fadump values' + Parameters + "#1" on fadump + "#2" nocma fadump + "#3" "" kdump + "#4" off kdump + End + It "should return the dump mode correctly" + When call get_dump_mode_by_fadump_val "$2" + The output should equal "$3" + The status should be success + End + End + + It 'should complain given invalid fadump value' + When call get_dump_mode_by_fadump_val /boot/vmlinuz + The status should be failure + The error should include 'invalid fadump' + End + + End + + End From 6506bd9b1bcd4117676aaef513c144c4d81bec21 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 21 Jan 2022 15:46:40 +0800 Subject: [PATCH 224/454] unit tests: add tests for kdumpctl read_proc_environ_var and _is_osbuild AfterAll is an example group hook [1] which would be run after the group tests are executed. Use this hook to clean up the files created by mktemp. [1] https://github.com/shellspec/shellspec#beforeall-afterall---example-group-hook Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_general_spec.sh | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index b968f74..9fbc1a0 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -70,5 +70,41 @@ Describe 'kdumpctl' End + Describe "read_proc_environ_var()" + environ_test_file=$(mktemp -t spec_test_environ_test_file.XXXXXXXXXX) + cleanup() { + rm -rf "$environ_test_file" + } + AfterAll 'cleanup' + echo -ne "container=bwrap-osbuild\x00SSH_AUTH_SOCK=/tmp/ssh-XXXXXXEbw33A/agent.1794\x00SSH_AGENT_PID=1929\x00env=test_env" >"$environ_test_file" + Parameters + container bwrap-osbuild + SSH_AUTH_SOCK /tmp/ssh-XXXXXXEbw33A/agent.1794 + env test_env + not_exist "" + End + It 'should read the environ variable value as expected' + When call read_proc_environ_var "$1" "$environ_test_file" + The output should equal "$2" + The status should be success + End + End + + Describe "_is_osbuild()" + environ_test_file=$(mktemp -t spec_test_environ_test_file.XXXXXXXXXX) + # shellcheck disable=SC2034 + # override the _OSBUILD_ENVIRON_PATH variable + _OSBUILD_ENVIRON_PATH="$environ_test_file" + Parameters + 'container=bwrap-osbuild' success + '' failure + End + It 'should be able to tell if it is the osbuild environment' + echo -ne "$1" >"$environ_test_file" + When call _is_osbuild + The status should be "$2" + The stderr should equal "" + End + End End From ea8b06df8392d71bdb694646a4e24fd29a947977 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 4 Jan 2022 20:57:55 +0800 Subject: [PATCH 225/454] unit tests: add tests for _{update,read}_kernel_arg_in_grub_etc_default in kdumpctl Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_general_spec.sh | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index 9fbc1a0..e72bf1d 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -107,4 +107,71 @@ Describe 'kdumpctl' End End + Describe '_update_kernel_arg_in_grub_etc_default()' + GRUB_ETC_DEFAULT=/tmp/default_grub + + cleanup() { + rm -rf "$GRUB_ETC_DEFAULT" + } + AfterAll 'cleanup' + + Context 'when the given parameter is in different positions' + Parameters + "crashkernel=222M fadump=on rhgb quiet" crashkernel 333M + " fadump=on crashkernel=222M rhgb quiet" crashkernel 333M + "fadump=on rhgb quiet crashkernel=222M" crashkernel 333M + "fadump=on rhgb quiet" crashkernel 333M + "fadump=on foo=bar1 rhgb quiet" foo bar2 + End + + It 'should update the kernel parameter correctly' + echo 'GRUB_CMDLINE_LINUX="'"$1"'"' >$GRUB_ETC_DEFAULT + When call _update_kernel_arg_in_grub_etc_default "$2" "$3" + # the updated kernel parameter should appear in the end + The contents of file $GRUB_ETC_DEFAULT should include "$2=$3\"" + End + End + + It 'should only update the given parameter and not update the parameter that has the given parameter as suffix' + echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT + _ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M + When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val" + The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\"" + The contents of file $GRUB_ETC_DEFAULT should include "ckcrashkernel=222M" + End + + It 'should be able to handle the cases of there are multiple crashkernel entries' + echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet crashkernel=101M crashkernel=222M"' >$GRUB_ETC_DEFAULT + _ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M + When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val" + The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\"" + The contents of file $GRUB_ETC_DEFAULT should not include "crashkernel=222M" + End + + Context 'when it removes a kernel parameter' + + It 'should remove all values for given arg' + echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M fadump=on crashkernel=222M"' >$GRUB_ETC_DEFAULT + When call _update_kernel_arg_in_grub_etc_default crashkernel + The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="fadump=on"' + End + + It 'should not remove args that have the given arg as suffix' + echo 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT + When call _update_kernel_arg_in_grub_etc_default crashkernel + The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M ckcrashkernel=222M"' + End + End + + End + + Describe '_read_kernel_arg_in_grub_etc_default()' + GRUB_ETC_DEFAULT=/tmp/default_grub + It 'should read the value for given arg' + echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT + When call _read_kernel_arg_in_grub_etc_default crashkernel + The output should equal '11M' + End + End + End From e00b45d75fa00a1d47b6cab0f609faf089ff563e Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 4 Jan 2022 15:24:34 +0800 Subject: [PATCH 226/454] unit tests: add tests for "kdumpctl reset-crashkernel" This commit adds a relatively thorough test suite for kdumpctl reset-crashkernel [--fadump=[on|off|nocma]] [--kernel=path_to_kernel] [--reboot] as implemented in commit 140da74 ("rewrite reset_crashkernel to support fadump and to used by RPM scriptlet"). grubby have a few options to support its own testing, - --no-etc-grub-update, not update /etc/default/grub - --bad-image-okay, don't check the validity of the image - --env, specify custom grub2 environment block file to avoid modifying the default /boot/grub2/grubenv - --bls-directory, specify custom BootLoaderSpec config files to avoid modifying the default /boot/loader/entries So the grubby called by kdumpctl is mocked as @grubby --grub2 --no-etc-grub-update --bad-image-okay --env=$SPEC_TEST_DIR/env_temp -b $SPEC_TEST_DIR/boot_load_entries "$@" in the tests. To be able to call the actual grubby in the mock function [1], ShellSpec provides the following command $ shellspec --gen-bin @grubby to generate spec/support/bins/@grubby which is used to call the actual grubby. kdumpctl has implemented its own version of updating /etc/default/grub in _update_kernel_cmdline_in_grub_etc_default. To avoiding writing to /etc/default/grub, this function is mocked as outputting its name and received arguments similar to python unitest's assert_called_with. [1] https://github.com/shellspec/shellspec#execute-the-actual-command-within-a-mock-function Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_reset_crashkernel_spec.sh | 224 ++++++++++++++++++ spec/support/bin/@grubby | 3 + ...846f63134c7295458cf36300ba5b-0-rescue.conf | 8 + ...58cf36300ba5b-5.14.14-200.fc34.x86_64.conf | 8 + ...458cf36300ba5b-5.15.6-100.fc34.x86_64.conf | 8 + spec/support/grub_env | 3 + 6 files changed, 254 insertions(+) create mode 100644 spec/kdumpctl_reset_crashkernel_spec.sh create mode 100755 spec/support/bin/@grubby create mode 100644 spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf create mode 100644 spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf create mode 100644 spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf create mode 100644 spec/support/grub_env diff --git a/spec/kdumpctl_reset_crashkernel_spec.sh b/spec/kdumpctl_reset_crashkernel_spec.sh new file mode 100644 index 0000000..28d9277 --- /dev/null +++ b/spec/kdumpctl_reset_crashkernel_spec.sh @@ -0,0 +1,224 @@ +#!/bin/bash +Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' + Include ./kdumpctl + kernel1=/boot/vmlinuz-5.15.6-100.fc34.x86_64 + kernel2=/boot/vmlinuz-5.14.14-200.fc34.x86_64 + ck=222M + KDUMP_SPEC_TEST_RUN_DIR=$(mktemp -d /tmp/spec_test.XXXXXXXXXX) + current_kernel=5.15.6-100.fc34.x86_64 + + setup() { + cp -r spec/support/boot_load_entries "$KDUMP_SPEC_TEST_RUN_DIR" + cp spec/support/grub_env "$KDUMP_SPEC_TEST_RUN_DIR"/env_temp + } + + cleanup() { + rm -rf "$KDUMP_SPEC_TEST_RUN_DIR" + } + + BeforeAll 'setup' + AfterAll 'cleanup' + + grubby() { + # - --no-etc-grub-update, not update /etc/default/grub + # - --bad-image-okay, don't check the validity of the image + # - --env, specify custom grub2 environment block file to avoid modifying + # the default /boot/grub2/grubenv + # - --bls-directory, specify custom BootLoaderSpec config files to avoid + # modifying the default /boot/loader/entries + @grubby --no-etc-grub-update --grub2 --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" + } + + Describe "Test the kdump dump mode " + uname() { + if [[ $1 == '-m' ]]; then + echo -n x86_64 + elif [[ $1 == '-r' ]]; then + echo -n $current_kernel + fi + } + kdump_crashkernel=$(get_default_crashkernel kdump) + Context "when --kernel not specified" + grubby --args crashkernel=$ck --update-kernel ALL + Specify 'kdumpctl should warn the user that crashkernel has been udpated' + When call reset_crashkernel + The error should include "Updated crashkernel=$kdump_crashkernel" + End + + Specify 'Current running kernel should have crashkernel updated' + When call grubby --info $kernel1 + The line 3 of output should include crashkernel="$kdump_crashkernel" + The line 3 of output should not include crashkernel=$ck + End + + Specify 'Other kernel still use the old crashkernel value' + When call grubby --info $kernel2 + The line 3 of output should include crashkernel=$ck + End + End + + Context "--kernel=ALL" + grubby --args crashkernel=$ck --update-kernel ALL + Specify 'kdumpctl should warn the user that crashkernel has been udpated' + When call reset_crashkernel --kernel=ALL + The error should include "Updated crashkernel=$kdump_crashkernel for kernel=$kernel1" + The error should include "Updated crashkernel=$kdump_crashkernel for kernel=$kernel2" + End + + Specify 'kernel1 should have crashkernel updated' + When call grubby --info $kernel1 + The line 3 of output should include crashkernel="$kdump_crashkernel" + End + + Specify 'kernel2 should have crashkernel updated' + When call grubby --info $kernel2 + The line 3 of output should include crashkernel="$kdump_crashkernel" + End + End + + Context "--kernel=/boot/one-kernel to update one specified kernel" + grubby --args crashkernel=$ck --update-kernel ALL + Specify 'kdumpctl should warn the user that crashkernel has been updated' + When call reset_crashkernel --kernel=$kernel1 + The error should include "Updated crashkernel=$kdump_crashkernel for kernel=$kernel1" + End + + Specify 'kernel1 should have crashkernel updated' + When call grubby --info $kernel1 + The line 3 of output should include crashkernel="$kdump_crashkernel" + End + + Specify 'kernel2 should have the old crashkernel' + When call grubby --info $kernel2 + The line 3 of output should include crashkernel=$ck + End + + End + + End + + Describe "FADump" fadump + uname() { + if [[ $1 == '-m' ]]; then + echo -n ppc64le + elif [[ $1 == '-r' ]]; then + echo -n $current_kernel + fi + } + + _update_kernel_arg_in_grub_etc_default() { + # don't modify /etc/default/grub during the test + echo _update_kernel_arg_in_grub_etc_default "$@" + } + + kdump_crashkernel=$(get_default_crashkernel kdump) + fadump_crashkernel=$(get_default_crashkernel fadump) + Context "when no --kernel specified" + grubby --args crashkernel=$ck --update-kernel ALL + grubby --remove-args=fadump --update-kernel ALL + Specify 'kdumpctl should warn the user that crashkernel has been udpated' + When call reset_crashkernel + The error should include "Updated crashkernel=$kdump_crashkernel" + End + + Specify 'Current running kernel should have crashkernel updated' + When call grubby --info $kernel1 + The line 3 of output should include crashkernel="$kdump_crashkernel" + End + + Specify 'Other kernel still use the old crashkernel value' + When call grubby --info $kernel2 + The line 3 of output should include crashkernel=$ck + End + End + + Context "--kernel=ALL --fadump=on" + grubby --args crashkernel=$ck --update-kernel ALL + Specify 'kdumpctl should warn the user that crashkernel has been udpated' + When call reset_crashkernel --kernel=ALL --fadump=on + The line 1 of output should include "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel" + The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1" + The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel2" + End + + Specify 'kernel1 should have crashkernel updated' + When call grubby --info $kernel1 + The line 3 of output should include crashkernel="$fadump_crashkernel" + End + + Specify 'kernel2 should have crashkernel updated' + When call get_grub_kernel_boot_parameter $kernel2 crashkernel + The output should equal "$fadump_crashkernel" + End + End + + Context "--kernel=/boot/one-kernel to update one specified kernel" + grubby --args crashkernel=$ck --update-kernel ALL + grubby --args fadump=on --update-kernel $kernel1 + Specify 'kdumpctl should warn the user that crashkernel has been updated' + When call reset_crashkernel --kernel=$kernel1 + The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1" + End + + Specify 'kernel1 should have crashkernel updated' + When call grubby --info $kernel1 + The line 3 of output should include crashkernel="$fadump_crashkernel" + End + + Specify 'kernel2 should have the old crashkernel' + When call get_grub_kernel_boot_parameter $kernel2 crashkernel + The output should equal $ck + End + End + + Context "Update all kernels but without --fadump specified" + grubby --args crashkernel=$ck --update-kernel ALL + grubby --args fadump=on --update-kernel $kernel1 + Specify 'kdumpctl should warn the user that crashkernel has been updated' + When call reset_crashkernel --kernel=$kernel1 + The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1" + End + + Specify 'kernel1 should have crashkernel updated' + When call get_grub_kernel_boot_parameter $kernel1 crashkernel + The output should equal "$fadump_crashkernel" + End + + Specify 'kernel2 should have the old crashkernel' + When call get_grub_kernel_boot_parameter $kernel2 crashkernel + The output should equal $ck + End + End + + Context 'Switch between fadump=on and fadump=nocma' + grubby --args crashkernel=$ck --update-kernel ALL + grubby --args fadump=on --update-kernel ALL + Specify 'fadump=on to fadump=nocma' + When call reset_crashkernel --kernel=ALL --fadump=nocma + The line 1 of output should equal "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel" + The line 2 of output should equal "_update_kernel_arg_in_grub_etc_default fadump nocma" + The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1" + The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel2" + End + + Specify 'kernel1 should have fadump=nocma in cmdline' + When call get_grub_kernel_boot_parameter $kernel1 fadump + The output should equal nocma + End + + Specify 'fadump=nocma to fadump=on' + When call reset_crashkernel --kernel=ALL --fadump=on + The line 1 of output should equal "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel" + The line 2 of output should equal "_update_kernel_arg_in_grub_etc_default fadump on" + The error should include "Updated fadump=on for kernel=$kernel1" + End + + Specify 'kernel2 should have fadump=on in cmdline' + When call get_grub_kernel_boot_parameter $kernel1 fadump + The output should equal on + End + + End + + End +End diff --git a/spec/support/bin/@grubby b/spec/support/bin/@grubby new file mode 100755 index 0000000..2a9b33f --- /dev/null +++ b/spec/support/bin/@grubby @@ -0,0 +1,3 @@ +#!/bin/sh -e +. "$SHELLSPEC_SUPPORT_BIN" +invoke grubby "$@" diff --git a/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf new file mode 100644 index 0000000..b821952 --- /dev/null +++ b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-0-rescue.conf @@ -0,0 +1,8 @@ +title Fedora (0-rescue-e986846f63134c7295458cf36300ba5b) 33 (Workstation Edition) +version 0-rescue-e986846f63134c7295458cf36300ba5b +linux /boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b +initrd /boot/initramfs-0-rescue-e986846f63134c7295458cf36300ba5b.img +options root=UUID=45fdf703-3966-401b-b8f7-cf056affd2b0 ro rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 crashkernel=4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-102400T:180G fadump=on +grub_users $grub_users +grub_arg --unrestricted +grub_class kernel diff --git a/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf new file mode 100644 index 0000000..08bd411 --- /dev/null +++ b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.14.14-200.fc34.x86_64.conf @@ -0,0 +1,8 @@ +title Fedora (5.14.14-200.fc34.x86_64) 34 (Workstation Edition) +version 5.14.14-200.fc34.x86_64 +linux /boot/vmlinuz-5.14.14-200.fc34.x86_64 +initrd /boot/initramfs-5.14.14-200.fc34.x86_64.img +options root=UUID=45fdf703-3966-401b-b8f7-cf056affd2b0 ro rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 crashkernel=4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-102400T:180G fadump=on +grub_users $grub_users +grub_arg --unrestricted +grub_class kernel diff --git a/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf new file mode 100644 index 0000000..9259b99 --- /dev/null +++ b/spec/support/boot_load_entries/e986846f63134c7295458cf36300ba5b-5.15.6-100.fc34.x86_64.conf @@ -0,0 +1,8 @@ +title Fedora (5.15.6-100.fc34.x86_64) 34 (Workstation Edition) +version 5.15.6-100.fc34.x86_64 +linux /boot/vmlinuz-5.15.6-100.fc34.x86_64 +initrd /boot/initramfs-5.15.6-100.fc34.x86_64.img +options root=UUID=45fdf703-3966-401b-b8f7-cf056affd2b0 ro rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 crashkernel=4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-102400T:180G fadump=on +grub_users $grub_users +grub_arg --unrestricted +grub_class fedora diff --git a/spec/support/grub_env b/spec/support/grub_env new file mode 100644 index 0000000..a77303c --- /dev/null +++ b/spec/support/grub_env @@ -0,0 +1,3 @@ +# GRUB Environment Block +# WARNING: Do not edit this file by tools other than grub-editenv!!! +################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################## \ No newline at end of file From e28a1399a3c9e60806a64216e6457e928a594dc8 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 6 Jan 2022 14:24:22 +0800 Subject: [PATCH 227/454] unit tests: add tests for kdump_get_conf_val in kdump-lib-initramfs.sh kdump_get_conf_val allows to retrieves config value defined in kdump.conf and it also supports sed regex like "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh". Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdump-lib-initramfs_spec.sh | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 spec/kdump-lib-initramfs_spec.sh diff --git a/spec/kdump-lib-initramfs_spec.sh b/spec/kdump-lib-initramfs_spec.sh new file mode 100644 index 0000000..dc50793 --- /dev/null +++ b/spec/kdump-lib-initramfs_spec.sh @@ -0,0 +1,41 @@ +#!/bin/bash +Describe 'kdump-lib-initramfs' + Include ./kdump-lib-initramfs.sh + + Describe 'Test kdump_get_conf_val' + KDUMP_CONFIG_FILE=/tmp/kdump_shellspec_test.conf + kdump_config() { + %text + #|default shell + #|nfs my.server.com:/export/tmp # trailing comment + #| failure_action shell + #|dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3" + #|sshkey /root/.ssh/kdump_id_rsa + #|ssh user@my.server.com + } + kdump_config >$KDUMP_CONFIG_FILE + Context 'Given different cases' + # Test the following cases: + # - there is trailing comment + # - there is space before the parameter + # - complicate value for dracut_args + # - Given two parameters, retrive one parameter that has value specified + # - Given two parameters (in reverse order), retrive one parameter that has value specified + Parameters + "#1" nfs my.server.com:/export/tmp + "#2" ssh user@my.server.com + "#3" failure_action shell + "#4" dracut_args '--omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3"' + "#5" 'ssh\|aaa' user@my.server.com + "#6" 'aaa\|ssh' user@my.server.com + End + + It 'should handle all cases correctly' + When call kdump_get_conf_val "$2" + The output should equal "$3" + End + End + + End + +End From 3d4cb38d96e45cf5da1460daf3345dd318fdee2f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 7 Jan 2022 16:00:08 +0800 Subject: [PATCH 228/454] unit tests: add check_config with with the default kdump.conf This test prevents the mistake of adding an option to kdump.conf without changing check_config as is the case with commit 73ced7f ("introduce the auto_reset_crashkernel option to kdump.conf"). Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_general_spec.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index e72bf1d..5a3ce1c 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -174,4 +174,29 @@ Describe 'kdumpctl' End End + Describe 'parse_config()' + bad_kdump_conf=$(mktemp -t bad_kdump_conf.XXXXXXXXXX) + cleanup() { + rm -f "$bad_kdump_conf" + } + AfterAll 'cleanup' + + It 'should not be happy with unkown option in kdump.conf' + KDUMP_CONFIG_FILE="$bad_kdump_conf" + echo blabla > "$bad_kdump_conf" + When call parse_config + The status should be failure + The stderr should include 'Invalid kdump config option blabla' + End + + It 'should be happy with the default kdump.conf' + # shellcheck disable=SC2034 + # override the KDUMP_CONFIG_FILE variable + KDUMP_CONFIG_FILE=./kdump.conf + When call parse_config + The status should be success + End + + End + End From a1c63fa6449740f771349f931748b0ccc8a67ec7 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 1 Mar 2022 17:35:39 +0800 Subject: [PATCH 229/454] add man documentation for kdumpctl get-default-crashkernel A few typos and grammar issues are fixed as well. Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl.8 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kdumpctl.8 b/kdumpctl.8 index 067117b..33c1115 100644 --- a/kdumpctl.8 +++ b/kdumpctl.8 @@ -14,7 +14,7 @@ In most cases, you should use .B systemctl to start / stop / enable kdump service instead. However, .B kdumpctl -provides more details for debug and a helper to setup ssh key authentication. +provides more details for debugging and a helper to set up ssh key authentication. .SH COMMANDS .TP @@ -26,14 +26,14 @@ Stop the service. .TP .I status Prints the current status of kdump service. -It returns non-zero value if kdump is not operational. +It returns a non-zero value if kdump is not operational. .TP .I restart Is equal to .I start; stop .TP .I reload -reload crash kernel image and initramfs without triggering a rebuild. +reload the crash kernel image and initramfs without triggering a rebuild. .TP .I rebuild rebuild the crash kernel initramfs. @@ -43,20 +43,23 @@ Helps to setup key authentication for ssh storage since it's impossible to use password authentication during kdump. .TP .I showmem -Prints the size of reserved memory for crash kernel in megabytes. +Prints the size of reserved memory for the crash kernel in megabytes. .TP .I estimate -Estimate a suitable crashkernel value for current machine. This is a -best-effort estimate. It will print a recommanded crashkernel value -based on current kdump setup, and list some details of memory usage. +Estimate a suitable crashkernel value for the current machine. This is a +best-effort estimate. It will print a recommended crashkernel value +based on the current kdump setup, and list some details of memory usage. +.TP +.I get-default-crashkernel +Return the default crashkernel value provided by kexec-tools. .TP .I reset-crashkernel [--kernel=path_to_kernel] [--reboot] Reset crashkernel to default value recommended by kexec-tools. If no kernel is specified, will reset KDUMP_KERNELVER if it's defined in /etc/sysconfig/kdump -or current running kernel's crashkernel value if KDUMP_KERNELVER is empty. You can +or the current running kernel's crashkernel value if KDUMP_KERNELVER is empty. You can also specify --kernel=ALL and --kernel=DEFAULT which have the same meaning as grubby's kernel-path=ALL and kernel-path=DEFAULT. ppc64le supports FADump and -supports an additonal [--fadump=[on|off|nocma]] parameter to toggle FADump +supports an additional [--fadump=[on|off|nocma]] parameter to toggle FADump on/off. Note: The memory requirements for kdump varies heavily depending on the From 683ff878213ea2a58971902f90f9dd77d4e64b8f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 18 Apr 2022 15:54:53 +0800 Subject: [PATCH 230/454] update crashkernel-howto 1. clean up left crashkernel.default 2. fix a few typos and grammar mistakes 3. ask the users to refer to `man kdumpctl` for reset-crashkernel Philipp Rudo Signed-off-by: Coiby Xu --- crashkernel-howto.txt | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/crashkernel-howto.txt b/crashkernel-howto.txt index 1ba79ab..94f4e52 100644 --- a/crashkernel-howto.txt +++ b/crashkernel-howto.txt @@ -37,10 +37,10 @@ Users can override the value during Anaconda installation manually. Auto update of crashkernel boot parameter ========================================= -A new release of kexec-tools could update the default crashkernel value. -By default, kexec-tools would reset crashkernel to the new default value if it -detects old default crashkernel value is used by installed kernels. If you don't -want kexec-tools to update the old default crashkernel to the new default +A new release of kexec-tools could update the default crashkernel value. By +default, kexec-tools would reset crashkernel to the new default value if it +detects the old default crashkernel value is used by installed kernels. If you +don't want kexec-tools to update the old default crashkernel to the new default crashkernel, you can change auto_reset_crashkernel to no in kdump.conf. Supported Bootloaders @@ -67,19 +67,18 @@ value properly, `kdumpctl` also provides a sub-command: `kdumpctl reset-crashkernel [--kernel=path_to_kernel] [--reboot]` -This command will read from the `crashkernel.default` file and reset -bootloader's kernel cmdline to the default value. It will also update bootloader -config if the bootloader has a standalone config file. User will have to reboot -the machine after this command to make it take effect if --reboot is not specified. -For ppc64le, an optional "[--fadump=[on|off|nocma]]" can also be specified to toggle -FADump on/off. +This command will reset the bootloader's kernel cmdline to the default value. +It will also update bootloader config if the bootloader has a standalone config +file. User will have to reboot the machine after this command to make it take +effect if --reboot is not specified. For more details, please refer to the +reset-crashkernel command in `man kdumpctl`. Reset manually -------------- To reset the crashkernel value manually, it's recommended to use utils like `grubby`. A one liner script for resetting `crashkernel=` value of all installed -kernels to current boot kernel's crashkernel.default` is: +kernels to the default value is: grubby --update-kernel ALL --args "crashkernel=$(kdumpctl get-default-crashkernel)" @@ -98,7 +97,7 @@ triggering kdump: The output will be like this: ``` - Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement + Encrypted kdump target requires extra memory, assuming using the keyslot with minimum memory requirement Reserved crashkernel: 256M Recommended crashkernel: 655M From 1e7df3e1f355da4fe0eca6422479963f7e772bf8 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 1 Mar 2022 17:30:50 +0800 Subject: [PATCH 231/454] update kexec-kdump-howto 1. yum is deprecated so use dnf instead 2. use the "kdumpctl reset-crashkernel" API 3. ask the users to refer to crashkernel-howto.txt for setting custom crashkernel value 4. fix a typo Philipp Rudo Signed-off-by: Coiby Xu --- kexec-kdump-howto.txt | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/kexec-kdump-howto.txt b/kexec-kdump-howto.txt index 1aeffc7..6741faf 100644 --- a/kexec-kdump-howto.txt +++ b/kexec-kdump-howto.txt @@ -44,7 +44,7 @@ ia64 and ppc64. If you're reading this document, you should already have kexec-tools installed. If not, you install it via the following command: - # yum install kexec-tools + # dnf install kexec-tools Now load a kernel with kexec: @@ -66,23 +66,31 @@ How to configure kdump Again, we assume if you're reading this document, you should already have kexec-tools installed. If not, you install it via the following command: - # yum install kexec-tools + # dnf install kexec-tools To be able to do much of anything interesting in the way of debug analysis, you'll also need to install the kernel-debuginfo package, of the same arch as your running kernel, and the crash utility: - # yum --enablerepo=\*debuginfo install kernel-debuginfo.$(uname -m) crash + # dnf --enablerepo=\*debuginfo install kernel-debuginfo.$(uname -m) crash -Next up, we need to modify some boot parameters to reserve a chunk of memory for -the capture kernel. With the help of grubby, it's very easy to append -"crashkernel=128M" to the end of your kernel boot parameters. Note that the X -values are such that X = the amount of memory to reserve for the capture kernel. -And based on arch and system configuration, one might require more than 128M to -be reserved for kdump. One need to experiment and test kdump, if 128M is not -sufficient, try reserving more memory. +Next up, we need to reserve a chunk of memory for the capture kernel. To use +the default crashkernel value, you can kdumpctl: - # grubby --args="crashkernel=128M" --update-kernel=/boot/vmlinuz-`uname -r` + # kdumpctl reset-crashkernel --kernel=/boot/vmlinuz-`uname -r` + +If the default value does not work for your setup you can use + + # grubby --args="crashkernel=256M" --update-kernel=/boot/vmlinuz-`uname -r` + +to specify a larger value, in this case 256M. You need to experiment to +find the best value that works for your setup. To begin with + + # kdumpctl estimate + +gives you an estimation for the crashkernel value based on the currently +running kernel. For more details, please refer to the "Estimate crashkernel" +section in /usr/share/doc/kexec-tools/crashkernel-howto.txt. Note that there is an alternative form in which to specify a crashkernel memory reservation, in the event that more control is needed over the size and @@ -135,7 +143,7 @@ in /var/crash//vmcore), then the system rebooted back into your normal kernel. Once back to your normal kernel, you can use the previously installed crash -kernel in conjunction with the previously installed kernel-debuginfo to +utility in conjunction with the previously installed kernel-debuginfo to perform postmortem analysis: # crash /usr/lib/debug/lib/modules/2.6.17-1.2621.el5/vmlinux From 695e5b8676ecbdf999ed535eae4074db8c3ef7aa Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 1 Mar 2022 17:30:30 +0800 Subject: [PATCH 232/454] update fadump-howto 1. yum is deprecated so use dnf instead 2. use the "kdumpctl reset-crashkernel --fadump=on" API Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- fadump-howto.txt | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/fadump-howto.txt b/fadump-howto.txt index bc87644..9773f78 100644 --- a/fadump-howto.txt +++ b/fadump-howto.txt @@ -39,7 +39,7 @@ kernel are one and the same on ppc64. If you're reading this document, you should already have kexec-tools installed. If not, you install it via the following command: - # yum install kexec-tools + # dnf install kexec-tools Fadump Operational Flow: @@ -82,7 +82,7 @@ How to configure fadump: Again, we assume if you're reading this document, you should already have kexec-tools installed. If not, you install it via the following command: - # yum install kexec-tools + # dnf install kexec-tools Make the kernel to be configured with FADump as the default boot entry, if it isn't already: @@ -94,20 +94,24 @@ anything interesting in the way of debug analysis, you'll also need to install the kernel-debuginfo package, of the same arch as your running kernel, and the crash utility: - # yum --enablerepo=\*debuginfo install kernel-debuginfo.$(uname -m) crash + # dnf --enablerepo=\*debuginfo install kernel-debuginfo.$(uname -m) crash -Next up, we need to modify some boot parameters to enable firmware assisted -dump. With the help of grubby, it's very easy to append "fadump=on" to the end -of your kernel boot parameters. To reserve the appropriate amount of memory -for boot memory preservation, pass 'crashkernel=X' kernel cmdline parameter. -For the recommended value of X, see 'FADump Memory Requirements' section. +Next up, we can enable firmware assisted dump and reserve the memory for boot +memory preservation as specified in in the table of 'FADump Memory Requirements' +section: + + # kdumpctl reset-crashkernel --fadump=on + +Alternatively, you can use grubby to reserve custom amount of memory: # grubby --args="fadump=on crashkernel=6G" --update-kernel=/boot/vmlinuz-`uname -r` By default, FADump reserved memory will be initialized as CMA area to make the memory available through CMA allocator on the production kernel. We can opt out of this, making reserved memory unavailable to production kernel, by booting the -linux kernel with 'fadump=nocma' instead of 'fadump=on'. +linux kernel with 'fadump=nocma' instead of 'fadump=on': + + # kdumpctl reset-crashkernel --fadump=nocma The term 'boot memory' means size of the low memory chunk that is required for a kernel to boot successfully when booted with restricted memory. By default, @@ -350,6 +354,6 @@ Remove "crashkernel=" from kernel cmdline parameters: If KDump is to be used as the dump capturing mechanism, reset the crashkernel parameter: - # kdumpctl reset-crashkernel `uname -r` + # kdumpctl reset-crashkernel --fadump=off Reboot the system for the settings to take effect. From be20580b06dc3fe92556933046ec8d2fd3a9b4b5 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 1 Mar 2022 17:33:24 +0800 Subject: [PATCH 233/454] remove the upper bound of default crashkernel value example Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- crashkernel-howto.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crashkernel-howto.txt b/crashkernel-howto.txt index 94f4e52..6573847 100644 --- a/crashkernel-howto.txt +++ b/crashkernel-howto.txt @@ -17,7 +17,7 @@ Latest kexec-tools provides "kdumpctl get-default-crashkernel" to retrieve the default crashkernel value, $ echo $(kdumpctl get-default-crashkernel) - 1G-4G:192M,4G-64G:256M,64G-102400T:512M + 1G-4G:192M,4G-64G:256M,64G-:512M It will be taken as the default value of 'crashkernel=', you can use this value as a reference for setting crashkernel value manually. From d5b01d7ef0f05c5ecb028aa1e8942ec099cbd9dd Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 24 Apr 2022 09:39:22 +0800 Subject: [PATCH 234/454] Release 2.0.24-2 A issue of bogus date in %changelog is fixed as well. Signed-off-by: Coiby Xu --- kexec-tools.spec | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index db6374c..8b1acf5 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.24 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -405,6 +405,21 @@ fi %endif %changelog +* Apr 24 2022 Coiby - 2.0.24-2 +- remove the upper bound of default crashkernel value example +- update fadump-howto +- update kexec-kdump-howto +- update crashkernel-howto +- add man documentation for kdumpctl get-default-crashkernel +- unit tests: add check_config with with the default kdump.conf +- unit tests: add tests for kdump_get_conf_val in kdump-lib-initramfs.sh +- unit tests: add tests for "kdumpctl reset-crashkernel" +- unit tests: add tests for _{update,read}_kernel_arg_in_grub_etc_default in kdumpctl +- unit tests: add tests for kdumpctl read_proc_environ_var and _is_osbuild +- unit tests: add tests for get_dump_mode_by_fadump_val +- unit tests: add tests for get_grub_kernel_boot_parameter +- unit tests: prepare for kdumpctl and kdump-lib.sh to be unit-tested + * Mon Apr 11 2022 Coiby - 2.0.24-1 - Update kexec-tools to 2.0.24 - kdumpctl: remove kdump_get_conf_val in save_raw @@ -472,7 +487,7 @@ fi - sysconfig: make kexec_file_load as default option on aarch64 - Enable zstd compression for makedumpfile in kexec-tools.spec -* Mon Nov 18 2021 Coiby - 2.0.23-1 +* Thu Nov 18 2021 Coiby - 2.0.23-1 - Update kexec-tools to 2.0.23 - Rebase makedumpfile to 1.7.0 - fix broken extra_bins when installing multiple binaries From 1facd0c11876bcbe83a9c52c67c1ce7a59f681dd Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 24 Apr 2022 11:38:04 +0800 Subject: [PATCH 235/454] fix incorrect date format in changelog Signed-off-by: Coiby Xu --- kexec-tools.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 8b1acf5..6673000 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -405,7 +405,7 @@ fi %endif %changelog -* Apr 24 2022 Coiby - 2.0.24-2 +* Sun Apr 24 2022 Coiby - 2.0.24-2 - remove the upper bound of default crashkernel value example - update fadump-howto - update kexec-kdump-howto From 3d70f8b04958c6f7a4a6b937fb828f9970d0c525 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Sat, 23 Apr 2022 21:07:31 +0800 Subject: [PATCH 236/454] logger: save log after all kdump progress finished Make log saving the last step of kdump.sh, so it can catch more info, for example, the output of post.d hooks will be covered by the log now. Signed-off-by: Kairui Song Reviewed-by: Philipp Rudo --- dracut-kdump.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index b17455a..f4456a1 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -15,6 +15,8 @@ fi KDUMP_PATH="/var/crash" KDUMP_LOG_FILE="/run/initramfs/kexec-dmesg.log" +KDUMP_LOG_DEST="" +KDUMP_LOG_OP="" CORE_COLLECTOR="" DEFAULT_CORE_COLLECTOR="makedumpfile -l --message-level 7 -d 31" DMESG_COLLECTOR="/sbin/vmcore-dmesg" @@ -113,12 +115,19 @@ get_kdump_confs() # store the kexec kernel log to a file. save_log() { + # LOG_OP is empty when log can't be saved, eg. raw target + [ -n "$KDUMP_LOG_OP" ] || return + dmesg -T > $KDUMP_LOG_FILE if command -v journalctl > /dev/null; then journalctl -ab >> $KDUMP_LOG_FILE fi chmod 600 $KDUMP_LOG_FILE + + dinfo "saving the $KDUMP_LOG_FILE to $KDUMP_LOG_DEST/" + + eval "$KDUMP_LOG_OP" } # $1: dump path, must be a mount point @@ -159,6 +168,9 @@ dump_fs() save_opalcore_fs "$_dump_fs_path" dinfo "saving vmcore" + KDUMP_LOG_DEST=$_dump_fs_path/ + KDUMP_LOG_OP="mv '$KDUMP_LOG_FILE' '$KDUMP_LOG_DEST/'" + $CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete" _dump_exitcode=$? if [ $_dump_exitcode -eq 0 ]; then @@ -167,12 +179,6 @@ dump_fs() dinfo "saving vmcore complete" else derror "saving vmcore failed, exitcode:$_dump_exitcode" - fi - - dinfo "saving the $KDUMP_LOG_FILE to $_dump_fs_path/" - save_log - mv "$KDUMP_LOG_FILE" "$_dump_fs_path/" - if [ $_dump_exitcode -ne 0 ]; then return 1 fi @@ -395,8 +401,12 @@ dump_ssh() ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1 save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2" + dinfo "saving vmcore" + KDUMP_LOG_DEST=$2:$_ssh_dir/ + KDUMP_LOG_OP="scp -q $_ssh_opt '$KDUMP_LOG_FILE' '$_scp_address:$_ssh_dir/'" + save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address" if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then @@ -421,12 +431,6 @@ dump_ssh() derror "saving vmcore failed, exitcode:$_ret" fi - dinfo "saving the $KDUMP_LOG_FILE to $2:$_ssh_dir/" - save_log - if ! scp -q $_ssh_opt $KDUMP_LOG_FILE "$_scp_address:$_ssh_dir/"; then - derror "saving log file failed, _exitcode:$_ret" - fi - return $_ret } @@ -576,6 +580,8 @@ if ! do_kdump_post $DUMP_RETVAL; then derror "kdump_post script exited with non-zero status!" fi +save_log + if [ $DUMP_RETVAL -ne 0 ]; then exit 1 fi From 5c23b6ebb79c5e06ff713d437cb54fb2843aa12d Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sat, 7 May 2022 16:30:39 +0800 Subject: [PATCH 237/454] fix a calculation error in get_system_size Recently, it's found 'kdumpctl estimate' returns 512M while the system reserves 1024M kdump memory in a case. This happens because the ranges in /proc/iomem are inclusively. For example, "0-1: System RAM" means 2 bytes of system memory other than 1 byte. Fix this error by adding one more byte. Note 1. the function has been simplified as well. 2. define PROC_IOMEM as /proc/iomem for the sake of unit tests Reported-by: Ruowen Qin Fixes: 1813189 ("kdump-lib.sh: introduce functions to return recommened mem size") Suggested-by: Philipp Rudo Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 557eff6..ed28df3 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -788,17 +788,12 @@ prepare_cmdline() echo "$cmdline" } -#get system memory size in the unit of GB +PROC_IOMEM=/proc/iomem +#get system memory size i.e. memblock.memory.total_size in the unit of GB get_system_size() { - result=$(grep "System RAM" /proc/iomem | awk -F ":" '{ print $1 }' | tr "[:lower:]" "[:upper:]" | paste -sd+) - result="+$result" - # replace '-' with '+0x' and '+' with '-0x' - sum=$(echo "$result" | sed -e 's/-/K0x/g' -e 's/+/-0x/g' -e 's/K/+/g') - size=$(printf "%d\n" $((sum))) - size=$((size / 1024 / 1024 / 1024)) - - echo "$size" + sum=$(sed -n "s/\s*\([0-9a-fA-F]\+\)-\([0-9a-fA-F]\+\) : System RAM$/+ 0x\2 - 0x\1 + 1/p" $PROC_IOMEM) + echo $(( (sum) / 1024 / 1024 / 1024)) } get_recommend_size() From 4f702c81e9d14a90d22d6b587de37733d0126960 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 12 May 2022 10:48:31 +0800 Subject: [PATCH 238/454] improve get_recommend_size This patch rewrites get_recommend_size to get rid of the following limitations, 1. only supports ranges in crashkernel sorted in increasing order 2. the first entry of crashkernel should have only a single digit and it's in gigabytes Suggested-by: Philipp Rudo Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index ed28df3..b137c89 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -796,33 +796,40 @@ get_system_size() echo $(( (sum) / 1024 / 1024 / 1024)) } +# Return the recommended size for the reserved crashkernel memory +# depending on the system memory size. +# +# This functions is expected to be consistent with the parse_crashkernel_mem() +# in kernel i.e. how kernel allocates the kdump memory given the crashkernel +# parameter crashkernel=range1:size1[,range2:size2,…] and the system memory +# size. get_recommend_size() { local mem_size=$1 local _ck_cmdline=$2 - local OLDIFS="$IFS" + local range start start_unit end end_unit size - start=${_ck_cmdline::1} - if [[ $mem_size -lt $start ]]; then - echo "0M" - return - fi - IFS=',' - for i in $_ck_cmdline; do - end=$(echo "$i" | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $1 }') - recommend=$(echo "$i" | awk -F "-" '{ print $2 }' | awk -F ":" '{ print $2 }') - size=${end::-1} - unit=${end: -1} - if [[ $unit == 'T' ]]; then - size=$((size * 1024)) - fi - if [[ $mem_size -lt $size ]]; then - echo "$recommend" - IFS="$OLDIFS" + while read -r -d , range; do + # need to use non-default IFS as double spaces are used as a + # single delimiter while commas aren't... + IFS=, read start start_unit end end_unit size <<< \ + "$(echo "$range" | sed -n "s/\([0-9]\+\)\([GT]\?\)-\([0-9]*\)\([GT]\?\):\([0-9]\+[MG]\)/\1,\2,\3,\4,\5/p")" + + # aka. 102400T + end=${end:-104857600} + [[ "$end_unit" == T ]] && end=$((end * 1024)) + [[ "$start_unit" == T ]] && start=$((start * 1024)) + + if [[ $mem_size -ge $start ]] && [[ $mem_size -lt $end ]]; then + echo "$size" return fi - done - IFS="$OLDIFS" + + # append a ',' as read expects the 'file' to end with a delimiter + done <<< "$_ck_cmdline," + + # no matching range found + echo "0M" } # get default crashkernel From 1101190e1cc11c25c50f26af61120154eeed1133 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 27 Apr 2022 19:17:32 +0800 Subject: [PATCH 239/454] unit tests: add tests for get_system_size and get_recommend_size Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- spec/kdump-lib_spec.sh | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 spec/kdump-lib_spec.sh diff --git a/spec/kdump-lib_spec.sh b/spec/kdump-lib_spec.sh new file mode 100644 index 0000000..8c91480 --- /dev/null +++ b/spec/kdump-lib_spec.sh @@ -0,0 +1,51 @@ +#!/bin/bash +Describe 'kdump-lib' + Include ./kdump-lib.sh + + Describe 'get_system_size()' + + PROC_IOMEM=$(mktemp -t spec_test_proc_iomem_file.XXXXXXXXXX) + + cleanup() { + rm -rf "$PROC_IOMEM" + } + + AfterAll 'cleanup' + + ONE_GIGABYTE='000000-3fffffff : System RAM' + Parameters + 1 + 3 + End + + It 'should return correct system RAM size' + echo -n >"$PROC_IOMEM" + for _ in $(seq 1 "$1"); do echo "$ONE_GIGABYTE" >>"$PROC_IOMEM"; done + When call get_system_size + The output should equal "$1" + End + + End + + Describe 'get_recommend_size()' + # Testing stragety: + # 1. inclusive for the lower bound of the range of crashkernel + # 2. exclusive for the upper bound of the range of crashkernel + # 3. supports ranges not sorted in increasing order + + ck="4G-64G:256M,2G-4G:192M,64G-1T:512M,1T-:12345M" + Parameters + 1 0M + 2 192M + 64 512M + 1024 12345M + "$((64 * 1024))" 12345M + End + + It 'should handle all cases correctly' + When call get_recommend_size "$1" $ck + The output should equal "$2" + End + End + +End From 218d9917c03f25bc9872f076491c587815d16efb Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Mon, 16 May 2022 14:04:12 -0400 Subject: [PATCH 240/454] kdump.sysconfig*: add ignition.firstboot to KDUMP_COMMANDLINE_REMOVE For CoreOS based systems we use Ignition for provisioning machines in the initramfs on first boot. We trigger Ignition right now by the presence of `ignition.firstboot` in the kernel command line. The kernel argument is only present on first boot so after a reboot it no longer is in the kernel command line. If a kernel crash happens before the first reboot of a machine we want the `ignition.firstboot` kernel argument to be removed and not passed on to the crash kernel. --- kdump.sysconfig | 2 +- kdump.sysconfig.aarch64 | 2 +- kdump.sysconfig.i386 | 2 +- kdump.sysconfig.ppc64 | 2 +- kdump.sysconfig.ppc64le | 2 +- kdump.sysconfig.s390x | 2 +- kdump.sysconfig.x86_64 | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kdump.sysconfig b/kdump.sysconfig index 70ebf04..c1143f3 100644 --- a/kdump.sysconfig +++ b/kdump.sysconfig @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE diff --git a/kdump.sysconfig.aarch64 b/kdump.sysconfig.aarch64 index 67a2af7..df75f94 100644 --- a/kdump.sysconfig.aarch64 +++ b/kdump.sysconfig.aarch64 @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE diff --git a/kdump.sysconfig.i386 b/kdump.sysconfig.i386 index 7e18c1c..d8bf5f6 100644 --- a/kdump.sysconfig.i386 +++ b/kdump.sysconfig.i386 @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE diff --git a/kdump.sysconfig.ppc64 b/kdump.sysconfig.ppc64 index ebb22f6..1b0cdc7 100644 --- a/kdump.sysconfig.ppc64 +++ b/kdump.sysconfig.ppc64 @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE diff --git a/kdump.sysconfig.ppc64le b/kdump.sysconfig.ppc64le index 270a2cf..d951def 100644 --- a/kdump.sysconfig.ppc64le +++ b/kdump.sysconfig.ppc64le @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE diff --git a/kdump.sysconfig.s390x b/kdump.sysconfig.s390x index 234cfe9..2971ae7 100644 --- a/kdump.sysconfig.s390x +++ b/kdump.sysconfig.s390x @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt ignition.firstboot" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE diff --git a/kdump.sysconfig.x86_64 b/kdump.sysconfig.x86_64 index 188ba3c..6a3ba6e 100644 --- a/kdump.sysconfig.x86_64 +++ b/kdump.sysconfig.x86_64 @@ -17,7 +17,7 @@ KDUMP_COMMANDLINE="" # This variable lets us remove arguments from the current kdump commandline # as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline # NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma" +KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE From 8f7ffb1a0054e48f833590d908a7d051008986f7 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 24 Apr 2022 09:47:26 +0800 Subject: [PATCH 241/454] Update makedumpfile to 1.7.1 Signed-off-by: Coiby Xu --- kexec-tools.spec | 6 +++--- sources | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 6673000..9b8218d 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,6 +1,6 @@ %global eppic_ver e8844d3793471163ae4a56d8f95897be9e5bd554 %global eppic_shortver %(c=%{eppic_ver}; echo ${c:0:7}) -%global mkdf_ver 1.7.0 +%global mkdf_ver 1.7.1 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools @@ -220,8 +220,8 @@ install -m 755 -D %{SOURCE33} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/92- %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile -install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.8.gz $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8.gz -install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf.5.gz $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5.gz +install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.8 $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8 +install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf.5 $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5 install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf $RPM_BUILD_ROOT/%{_sysconfdir}/makedumpfile.conf.sample install -m 755 makedumpfile-%{mkdf_ver}/eppic_makedumpfile.so $RPM_BUILD_ROOT/%{_libdir}/eppic_makedumpfile.so mkdir -p $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ diff --git a/sources b/sources index 95c0fc6..d0190bb 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 SHA512 (kexec-tools-2.0.24.tar.xz) = ef7cf78246e2d729d81a3649791a5a23c385353cc75cbe8ef279616329fdaccc876d614c7f51e1456822a13a11520296070d9897467d24310399909e049c3822 -SHA512 (makedumpfile-1.7.0.tar.gz) = 579a1fb79d023a1419fc8612a02a04dda3e3b3d72455566433ab6bec08627aa9a176c55566393a081a7aae3fd0543800196596b25445b21b16346556723e9cf7 +SHA512 (makedumpfile-1.7.1.tar.gz) = 93e36487b71f567d3685b151459806cf36017e52bf3ee68dd448382b279a422d1a8abef72e291ccb8206f2149ccd08ba484ec0027d1caab3fa1edbc3d28c3632 From 6f9653b9183b710008b8271e6cc51ea47c2585bd Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 24 Apr 2022 09:48:05 +0800 Subject: [PATCH 242/454] Release 2.0.24-3 Signed-off-by: Coiby Xu --- kexec-tools.spec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 9b8218d..9c6ea8d 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.24 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -405,6 +405,13 @@ fi %endif %changelog +* Mon May 23 2022 Coiby - 2.0.24-3 +- Update makedumpfile to 1.7.1 +- unit tests: add tests for get_system_size and get_recommend_size +- improve get_recommend_size +- fix a calculation error in get_system_size +- logger: save log after all kdump progress finished + * Sun Apr 24 2022 Coiby - 2.0.24-2 - remove the upper bound of default crashkernel value example - update fadump-howto From c5bdd2d8f195103d6651f7fa3b429f4edf204956 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Mon, 13 Jun 2022 12:08:08 +0800 Subject: [PATCH 243/454] kdump-lib: use non-debug kernels first Kdump uses currently running kernel as default, but when currently running kernel is a debug kernel, it will consume more memory, which may cause out-of-memory and fail to collect vmcore. Now we will try to use non-debug kernels first if possible. Also extract the logic of determine KDUMP_KERNEL from prepare_kdump_bootinfo into a function. This function will return KDUMP_KERNEL given a kernel version. Signed-off-by: Lichen Liu Acked-by: Coiby Xu --- kdump-lib.sh | 71 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index b137c89..944d823 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -633,8 +633,36 @@ prepare_kexec_args() echo "$kexec_args" } +# prepare_kdump_kernel +# This function return kdump_kernel given a kernel version. +prepare_kdump_kernel() +{ + local kdump_kernelver=$1 + local dir img boot_dirlist boot_imglist kdump_kernel machine_id + read -r machine_id < /etc/machine-id + + boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"} + boot_imglist="$KDUMP_IMG-$kdump_kernelver$KDUMP_IMG_EXT $machine_id/$kdump_kernelver/$KDUMP_IMG" + + # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format + boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)" + if [[ "$boot_img" == *"$kdump_kernelver" ]]; then + boot_imglist="$boot_img $boot_imglist" + fi + + for dir in $boot_dirlist; do + for img in $boot_imglist; do + if [[ -f "$dir/$img" ]]; then + kdump_kernel=$(echo "$dir/$img" | tr -s '/') + break 2 + fi + done + done + echo "$kdump_kernel" +} + # -# Detect initrd and kernel location, results are stored in global enviromental variables: +# Detect initrd and kernel location, results are stored in global environmental variables: # KDUMP_BOOTDIR, KDUMP_KERNELVER, KDUMP_KERNEL, DEFAULT_INITRD, and KDUMP_INITRD # # Expectes KDUMP_BOOTDIR, KDUMP_IMG, KDUMP_IMG_EXT, KDUMP_KERNELVER to be loaded from config already @@ -642,37 +670,40 @@ prepare_kexec_args() # prepare_kdump_bootinfo() { - local boot_img boot_imglist boot_dirlist boot_initrdlist - local machine_id dir img default_initrd_base var_target_initrd_dir + local boot_initrdlist nondebug_kernelver debug_kernelver + local default_initrd_base var_target_initrd_dir if [[ -z $KDUMP_KERNELVER ]]; then - KDUMP_KERNELVER="$(uname -r)" + KDUMP_KERNELVER=$(uname -r) + nondebug_kernelver=$(sed -n -e 's/\(.*\)+debug$/\1/p' <<< "$KDUMP_KERNELVER") fi - read -r machine_id < /etc/machine-id - boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"} - boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG" - - # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format - boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)" - if [[ -n $boot_img ]]; then - boot_imglist="$boot_img $boot_imglist" + # Use nondebug kernel if possible, because debug kernel will consume more memory and may oom. + if [[ -n $nondebug_kernelver ]]; then + dinfo "Trying to use $nondebug_kernelver." + debug_kernelver=$KDUMP_KERNELVER + KDUMP_KERNELVER=$nondebug_kernelver fi - for dir in $boot_dirlist; do - for img in $boot_imglist; do - if [[ -f "$dir/$img" ]]; then - KDUMP_KERNEL=$(echo "$dir/$img" | tr -s '/') - break 2 - fi - done - done + KDUMP_KERNEL=$(prepare_kdump_kernel "$KDUMP_KERNELVER") + + if ! [[ -e $KDUMP_KERNEL ]]; then + if [[ -n $debug_kernelver ]]; then + dinfo "Fallback to using debug kernel" + KDUMP_KERNELVER=$debug_kernelver + KDUMP_KERNEL=$(prepare_kdump_kernel "$KDUMP_KERNELVER") + fi + fi if ! [[ -e $KDUMP_KERNEL ]]; then derror "Failed to detect kdump kernel location" return 1 fi + if [[ "$KDUMP_KERNEL" == *"+debug" ]]; then + dwarn "Using debug kernel, you may need to set a larger crashkernel than the default value." + fi + # Set KDUMP_BOOTDIR to where kernel image is stored KDUMP_BOOTDIR=$(dirname "$KDUMP_KERNEL") From b92bc6e0a775255e545506cedfa6946a1a104eff Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Mon, 13 Jun 2022 10:25:26 +0800 Subject: [PATCH 244/454] crashkernel: optimize arm64 reserved size if PAGE_SIZE=4k On RHEL9 and Fedora, the arm64 platform only supports 4KB page size. the reserved memory size can be aligned to that on x86_64. Introducing a new formula for 4KB on arm64, which bases on x86_64 plus extra 64MB. Signed-off-by: Pingfan Liu Acked-by: Baoquan He --- kdump-lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 944d823..36437ab 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -884,7 +884,8 @@ kdump_get_arch_recommend_crashkernel() if [[ $_arch == "x86_64" ]] || [[ $_arch == "s390x" ]]; then _ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M" elif [[ $_arch == "aarch64" ]]; then - _ck_cmdline="2G-:448M" + # For 4KB page size, the formula is based on x86 plus extra = 64M + _ck_cmdline="1G-4G:256M,4G-64G:320M,64G-:576M" elif [[ $_arch == "ppc64le" ]]; then if [[ $_dump_mode == "fadump" ]]; then _ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" From 980f10aa40852da41907dc0aeb59ad7d3e8f4c30 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Wed, 22 Jun 2022 11:58:31 -0400 Subject: [PATCH 245/454] kdump-lib: clear up references to Atomic/CoreOS There are many variants on OSTree based systems these days so we should probably refer to the class of systems as "OSTree based systems". Also, Atomic Host is dead. Signed-off-by: Dusty Mabe Acked-by: Coiby Xu --- kdump-lib.sh | 2 +- kdumpctl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 36437ab..91b3226 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -248,7 +248,7 @@ kdump_get_persistent_dev() echo $(get_persistent_dev "$dev") } -is_atomic() +is_ostree() { grep -q "ostree" /proc/cmdline } diff --git a/kdumpctl b/kdumpctl index 6188d47..2157371 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1342,7 +1342,7 @@ _update_grub() { local _kernel_path=$1 _crashkernel=$2 _dump_mode=$3 _fadump_val=$4 - if is_atomic; then + if is_ostree; then if rpm-ostree kargs | grep -q "crashkernel="; then rpm-ostree kargs --replace="crashkernel=$_crashkernel" else @@ -1472,13 +1472,13 @@ reset_crashkernel() esac done - # 1. CoreOS uses "rpm-ostree kargs" instead of grubby to manage kernel command - # line. --kernel=ALL doesn't make sense for CoreOS. - # 2. CoreOS doesn't support POWER so the dump mode is always kdump. + # 1. OSTree systems use "rpm-ostree kargs" instead of grubby to manage kernel command + # line. --kernel=ALL doesn't make sense for OStree. + # 2. We don't have any OSTree POWER systems so the dump mode is always kdump. # 3. "rpm-ostree kargs" would prompt the user to reboot the system after # modifying the kernel command line so there is no need for kexec-tools # to repeat it. - if is_atomic; then + if is_ostree; then _old_crashkernel=$(rpm-ostree kargs | sed -n -E 's/.*(^|\s)crashkernel=(\S*).*/\2/p') _new_dump_mode=kdump _new_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") From a1ebf0b5654625cd7a80a3b368080d4f56088537 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Fri, 24 Jun 2022 09:57:03 -0400 Subject: [PATCH 246/454] kdump-lib: change how ostree based systems are detected The current recommendation is to check for /run/ostree-booted. See https://bugzilla.redhat.com/show_bug.cgi?id=2092012#c0 Signed-off-by: Dusty Mabe Acked-by: Coiby Xu --- kdump-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 91b3226..a48ff8a 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -250,7 +250,7 @@ kdump_get_persistent_dev() is_ostree() { - grep -q "ostree" /proc/cmdline + test -f /run/ostree-booted } # get ip address or hostname from nfs/ssh config value From f9c32372d2c8d5e58024d2ddc0b70498c696b5d8 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Wed, 22 Jun 2022 12:34:12 -0400 Subject: [PATCH 247/454] kdump-lib: attempt to fix BOOT_IMAGE detection Currently $boot_img can get bad data if running on a platform that doesn't set BOOT_IMAGE in the kernel command line. For example, currently: - s390x Fedora CoreOS machine: ``` [root@cosa-devsh ~]# sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline mitigations=auto,nosmt ignition.platform.id=qemu ostree=/ostree/boot.0/fedora-coreos/2a72567ac8f7ed678c3ac89408f795e6ccd4e97b41e14af5f471b6a807e858b9/0 root=UUID=2a88436a-3b6b-4706-b33a-b8270bd87cde rw rootflags=prjquota boot=UUID=f4b2eaa5-9317-4798-85cf-308c477fee4c crashkernel=600M ``` where on a platform that uses GRUB we get: - x86_64 Fedora CoreOS machine: ``` [root@cosa-devsh ~]# sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline /ostree/fedora-coreos-af4f6cc7b9ff486cfa647680b180e989c72c8eed03a34a42e7328e49332bd20e/vmlinuz-5.18.5-200.fc36.x86_64 ``` We should change the setting of the boot_img variable such that it will be empty if BOOT_IMAGE doesn't exist. With this change on the s390x machine: ``` [root@cosa-devsh ~]# grep -P -o '^BOOT_IMAGE=(\S+)' /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\)/\2/" [root@cosa-devsh ~]# ``` This change mattered much more before the change in c5bdd2d which changed the following line from [[ -n $boot_img ]] to [[ "$boot_img" == *"$kdump_kernelver" ]]. Still I think this change has merit. Signed-off-by: Dusty Mabe Acked-by: Coiby Xu --- kdump-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index a48ff8a..1c1dcea 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -645,7 +645,7 @@ prepare_kdump_kernel() boot_imglist="$KDUMP_IMG-$kdump_kernelver$KDUMP_IMG_EXT $machine_id/$kdump_kernelver/$KDUMP_IMG" # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format - boot_img="$(sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/" /proc/cmdline)" + boot_img="$(grep -P -o '^BOOT_IMAGE=(\S+)' /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\)/\2/")" if [[ "$boot_img" == *"$kdump_kernelver" ]]; then boot_imglist="$boot_img $boot_imglist" fi From ed9cbec2ee263b181ea0023c60b392c37c20071b Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Tue, 21 Jun 2022 16:55:09 +0800 Subject: [PATCH 248/454] kdump-lib: Add the CoreOS kernel dir to the boot_dirlist The kernel of CoreOS is not in the standard locations, add /boot/ostree/* to the boot_dirlist to find the vmlinuz. Signed-off-by: Lichen Liu Acked-by: Coiby Xu --- kdump-lib.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 1c1dcea..f7b659e 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -644,6 +644,11 @@ prepare_kdump_kernel() boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"} boot_imglist="$KDUMP_IMG-$kdump_kernelver$KDUMP_IMG_EXT $machine_id/$kdump_kernelver/$KDUMP_IMG" + # The kernel of OSTree based systems is not in the standard locations. + if is_ostree; then + boot_dirlist="$(echo /boot/ostree/*) $boot_dirlist" + fi + # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format boot_img="$(grep -P -o '^BOOT_IMAGE=(\S+)' /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\)/\2/")" if [[ "$boot_img" == *"$kdump_kernelver" ]]; then From 1913ea9118f855f27b89907977f9eb5fdb7ce61b Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Thu, 14 Jul 2022 18:55:31 +0800 Subject: [PATCH 249/454] Checking the existence of 40-redhat.rules before modifying Resolves: bz2106645 The code of commit 163c02970e4ddc takes effect in rhel firstly, later pulled to Fedora. However, Fedora OS doesn't have 40-redhat.rules in systemd-udev package. With this commit applied, a false positive warning message can always been seen as below. So fixing it by checking if 40-redhat.rules exists before handling. With this change, the false warning is gone. [root@ ~]# kdumpctl restart kdump: kexec: unloaded kdump kernel kdump: Stopping kdump: [OK] kdump: No kdump initial ramdisk found. kdump: Rebuilding /boot/initramfs-5.19.0-rc6+kdump.img sed: can't read /var/tmp/dracut.NnAV2g/initramfs/usr/lib/udev/rules.d/40-redhat.rules: No such file or directory kdump: kexec: loaded kdump kernel kdump: Starting kdump: [OK] Signed-off-by: Baoquan He Acked-by: Pingfan Liu --- dracut-module-setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index c319fc2..4c6096a 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1013,7 +1013,9 @@ kdump_install_systemd_conf() { remove_cpu_online_rule() { local file=${initdir}/usr/lib/udev/rules.d/40-redhat.rules - sed -i '/SUBSYSTEM=="cpu"/d' "$file" + if [[ -f $file ]]; then + sed -i '/SUBSYSTEM=="cpu"/d' "$file" + fi } install() { From c735539b3549ca29ca72d824de5a3226ee8fc17f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 21 Jul 2022 16:42:34 +0800 Subject: [PATCH 250/454] Release 2.0.24-4 Signed-off-by: Coiby Xu --- kexec-tools.spec | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 9c6ea8d..c6e42b2 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.24 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -405,6 +405,15 @@ fi %endif %changelog +* Thu Jul 21 2022 Coiby - 2.0.24-4 +- Checking the existence of 40-redhat.rules before modifying +- kdump-lib: Add the CoreOS kernel dir to the boot_dirlist +- kdump-lib: attempt to fix BOOT_IMAGE detection +- kdump-lib: change how ostree based systems are detected +- kdump-lib: clear up references to Atomic/CoreOS +- crashkernel: optimize arm64 reserved size if PAGE_SIZE=4k +- kdump-lib: use non-debug kernels first + * Mon May 23 2022 Coiby - 2.0.24-3 - Update makedumpfile to 1.7.1 - unit tests: add tests for get_system_size and get_recommend_size From d593bfa6fc5e2e894798e22fa9c4c433517de4b3 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Thu, 21 Jul 2022 19:00:19 +0800 Subject: [PATCH 251/454] KDUMP_COMMANDLINE: remove irqpoll parameter on aws aarch64 platform Currently, kdump may experience failure on some aws aarch64 platform. The final scenario is: [ 79.145089] printk: console [ttyS0] disabled Then the system has no response any more. And after reboot, there is no vmcore generated under /var/crash/. More detail [1]. In a short word, it is caused by the irqpoll policy and some unknown acpi issue. The serial device is hot-removed as a pci device. More detailed, the irqpoll policy demands to iterate over all interrupt handler, if the interrupt line is shared, then the handler is dispatched. And acpi handler acpi_irq() is on a shared interrupt line, so it is called. But for some unknown reason, the acpi hardware regs hold wrong state, and the acpi driver decides that a hot-removed event happens on a pci slot, which finally removes the pci serial device. To tackle this issue by removing the irqpoll parameter on aws aarch64 platform, until the real root cause in acpi is found and resolved. [1]: https://bugzilla.redhat.com/show_bug.cgi?id=2080468#c0 Signed-off-by: Pingfan Liu Acked-by: Coiby Xu --- kdumpctl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kdumpctl b/kdumpctl index 2157371..7ff635c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -641,6 +641,18 @@ function remove_kdump_kernel_key() keyctl unlink "$KDUMP_KEY_ID" %:.ima } +function is_aws_aarch64() +{ + local _bios_model + + _bios_model=$(lscpu | grep "BIOS Model name") + if [[ "${_bios_model}" =~ "AWS Graviton" ]]; then + return 0 + fi + + return 1 +} + # Load the kdump kernel specified in /etc/sysconfig/kdump # If none is specified, try to load a kdump kernel with the same version # as the currently running kernel. @@ -650,6 +662,10 @@ load_kdump() KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") KDUMP_COMMANDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}") + # This is a workaround on AWS platform, since irqpoll may cause the hot-remove of some pci hotplug device + if is_aws_aarch64; then + KDUMP_COMMANDLINE=$(remove_cmdline_param "${KDUMP_COMMANDLINE}" irqpoll) + fi # For secureboot enabled machines, use new kexec file based syscall. # Old syscall will always fail as it does not have capability to From da0ca0d205e7ac64426ad43540dae3d03cd4447a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 28 Jun 2022 14:38:28 +0800 Subject: [PATCH 252/454] Allow to update kexec-tools using virt-customize for cloud base image Resolves: bz2089871 Currently, kexec-tools can't be updated using virt-customize because older version of kdumpctl can't acquire instance lock for the get-default-crashkernel subcommand. The reason is /var/lock is linked to /run/lock which however doesn't exist in the case of virt-customize. This patch fixes this problem by using /tmp/kdump.lock as the lock file if /run/lock doesn't exist. Note 1. The lock file is now created in /run/lock instead of /var/run/lock since Fedora has adopted adopted /run [2] since F15. 2. %pre scriptlet now always return success since package update won't be blocked [1] https://fedoraproject.org/wiki/Features/var-run-tmpfs Fixes: 0adb0f4 ("try to reset kernel crashkernel when kexec-tools updates the default crashkernel value") Reported-by: Nicolas Hicher Suggested-by: Laszlo Ersek Suggested-by: Philipp Rudo Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdumpctl | 11 +++++++++-- kexec-tools.spec | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 7ff635c..fed55bd 100755 --- a/kdumpctl +++ b/kdumpctl @@ -49,9 +49,16 @@ fi single_instance_lock() { - local rc timeout=5 + local rc timeout=5 lockfile - if ! exec 9> /var/lock/kdump; then + if [[ -d /run/lock ]]; then + lockfile=/run/lock/kdump + else + # when updating package using virt-customize, /run/lock doesn't exist + lockfile=/tmp/kdump.lock + fi + + if ! exec 9> $lockfile; then derror "Create file lock failed" exit 1 fi diff --git a/kexec-tools.spec b/kexec-tools.spec index c6e42b2..bdc3b95 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -269,6 +269,8 @@ if ! grep -qs "ostree" /proc/cmdline && [ $1 == 2 ] && grep -q get-default-crash kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null %endif fi +# don't block package update +: %post # Initial installation From f6bcd819fc2645f762946a802c15684e7627f379 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 15 Jul 2022 15:11:44 +0800 Subject: [PATCH 253/454] use /run/ostree-booted to tell if scriptlet is running on OSTree system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: bz2092012 According to the ostree team [1], the existence of /run/ostree-booted > is the most stable way to signal/check that a system has been > booted in ostree-style. It is also used by rpm-ostree at > compose/install time in the sandboxed environment where scriptlets run, > in order to signal that the package is being installed/composed into > an ostree commit (i.e. not directly on a live system). See > https://github.com/coreos/rpm-ostree/blob/8ddf5f40d9cbbd9d3668cc75b703316e0a89ab11/src/libpriv/rpmostree-scripts.cxx#L350-L353 > for reference. By checking the existence of /run/ostree-booted, we could skip trying to update kernel cmdline during OSTree compose time. [1] https://bugzilla.redhat.com/show_bug.cgi?id=2092012#c3 Reported-by: Luca BRUNO Suggested-by: Luca BRUNO Fixes: 0adb0f4 ("try to reset kernel crashkernel when kexec-tools updates the default crashkernel value") Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Acked-by: Timothée Ravier --- kexec-tools.spec | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index bdc3b95..c82bea8 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -262,8 +262,12 @@ mkdir -p $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ %pre -# save the old default crashkernel values to /tmp/ when upgrading the package -if ! grep -qs "ostree" /proc/cmdline && [ $1 == 2 ] && grep -q get-default-crashkernel /usr/bin/kdumpctl; then +# Save the old default crashkernel values to /tmp/ when upgrading the package +# so kdumpctl later can tell if it should update the kernel crashkernel +# parameter in the posttrans scriptlet. Note this feauture of auto-updating +# the kernel crashkernel parameter currently doesn't support ostree, so skip it +# for ostree. +if [ ! -f /run/ostree-booted ] && [ $1 == 2 ] && grep -q get-default-crashkernel /usr/bin/kdumpctl; then kdumpctl get-default-crashkernel kdump > /tmp/old_default_crashkernel 2>/dev/null %ifarch ppc64 ppc64le kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null @@ -338,9 +342,14 @@ do done %posttrans -# try to reset kernel crashkernel value to new default value when upgrading -# the package -if ! grep -qs "ostree" /proc/cmdline && [ $1 == 1 ]; then +# Try to reset kernel crashkernel value to new default value based on the old +# default value or set up crasherkernel value for osbuild +# +# Note +# 1. Skip ostree systems as they are not supported. +# 2. "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade. The +# former case is used to set up crashkernel for osbuild +if [ ! -f /run/ostree-booted ] && [ $1 == 1 ]; then kdumpctl reset-crashkernel-after-update rm /tmp/old_default_crashkernel 2>/dev/null %ifarch ppc64 ppc64le From e8ae8975958d2b2d2a5f3853d82cdd95ef4bb653 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 12 Jul 2022 14:06:25 +0800 Subject: [PATCH 254/454] skip updating /etc/default/grub for s390x Resolves: bz2104534 When running "kdumpctl reset-crashkernel --kernel=ALL" on s390x, sed: can't read /etc/default/grub: No such file or directory sed: can't read /etc/default/grub: No such file or directory This happens because s390x doesn't use the grub bootloader and /etc/default/grub doesn't exist. Reported-by: smitterl@redhat.com Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kdumpctl b/kdumpctl index fed55bd..1b4b261 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1428,6 +1428,10 @@ _update_kernel_arg_in_grub_etc_default() { local _para=$1 _val=$2 _para_val + if [[ $(uname -m) == s390x ]]; then + return + fi + if [[ -n $_val ]]; then _para_val="$_para=$_val" fi From 58eef4582a5ec060a51a699839868d5b86fa2b05 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 12 Jul 2022 16:07:37 +0800 Subject: [PATCH 255/454] remove useless --zipl when calling grubby to update kernel command line "grubby --zipl" only takes effect when setting default kernel. It's useless to add "--zipl" when updating kernel command line. Also rename _update_grub to _update_kernel_cmdline since s390x doesn't use GRUB. Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kdumpctl b/kdumpctl index 1b4b261..126ecb9 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1361,7 +1361,7 @@ _get_current_running_kernel_path() fi } -_update_grub() +_update_kernel_cmdline() { local _kernel_path=$1 _crashkernel=$2 _dump_mode=$3 _fadump_val=$4 @@ -1372,15 +1372,14 @@ _update_grub() rpm-ostree kargs --append="crashkernel=$_crashkernel" fi else - [[ -f /etc/zipl.conf ]] && zipl_arg="--zipl" - grubby --args "crashkernel=$_crashkernel" --update-kernel "$_kernel_path" $zipl_arg + grubby --args "crashkernel=$_crashkernel" --update-kernel "$_kernel_path" if [[ $_dump_mode == kdump ]]; then grubby --remove-args="fadump" --update-kernel "$_kernel_path" else grubby --args="fadump=$_fadump_val" --update-kernel "$_kernel_path" fi fi - [[ $zipl_arg ]] && zipl > /dev/null + [[ -f /etc/zipl.conf ]] && zipl > /dev/null } _valid_grubby_kernel_path() @@ -1510,7 +1509,7 @@ reset_crashkernel() _new_dump_mode=kdump _new_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") if [[ $_old_crashkernel != "$_new_crashkernel" ]]; then - _update_grub "" "$_new_crashkernel" "$_new_dump_mode" "" + _update_kernel_cmdline "" "$_new_crashkernel" "$_new_dump_mode" "" if [[ $_reboot == yes ]]; then systemctl reboot fi @@ -1578,7 +1577,7 @@ reset_crashkernel() _old_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) _old_fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) if [[ $_old_crashkernel != "$_new_crashkernel" || $_old_fadump_val != "$_new_fadump_val" ]]; then - _update_grub "$_kernel" "$_new_crashkernel" "$_new_dump_mode" "$_new_fadump_val" + _update_kernel_cmdline "$_kernel" "$_new_crashkernel" "$_new_dump_mode" "$_new_fadump_val" if [[ $_reboot != yes ]]; then if [[ $_old_crashkernel != "$_new_crashkernel" ]]; then _what_is_updated="Updated crashkernel=$_new_crashkernel" @@ -1647,7 +1646,7 @@ reset_crashkernel_after_update() if [[ $_crashkernel == "$_old_default_crashkernel" ]] && [[ $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) - if _update_grub "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then + if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then echo "For kernel=$_kernel, crashkernel=$_new_default_crashkernel now." fi fi @@ -1703,7 +1702,7 @@ reset_crashkernel_for_installed_kernel() _fadump_val_running=$(get_grub_kernel_boot_parameter "$_kernel" fadump) if [[ $_crashkernel != "$_crashkernel_running" ]]; then - if _update_grub "$_installed_kernel" "$_crashkernel_running" "$_dump_mode_running" "$_fadump_val_running"; then + if _update_kernel_cmdline "$_installed_kernel" "$_crashkernel_running" "$_dump_mode_running" "$_fadump_val_running"; then echo "kexec-tools has reset $_installed_kernel to use the new default crashkernel value $_crashkernel_running" fi fi From 4d1e02d3405c92a6d474042572313181d8753595 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 12 Jul 2022 10:52:10 +0800 Subject: [PATCH 256/454] remind the users to run zipl after calling grubby on s390x s390x doesn't use GRUB. To make sure the boot entries are updated, call zipl after running grubby. Suggested-by: smitterl@redhat.com Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- crashkernel-howto.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crashkernel-howto.txt b/crashkernel-howto.txt index 6573847..54e1141 100644 --- a/crashkernel-howto.txt +++ b/crashkernel-howto.txt @@ -82,6 +82,8 @@ kernels to the default value is: grubby --update-kernel ALL --args "crashkernel=$(kdumpctl get-default-crashkernel)" +NOTE: On s390x you also need to run zipl for the change to take effect. + Estimate crashkernel ==================== From d347ad591fea5296403cdcab6c5377b22d6acaee Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 14 Oct 2021 13:12:56 +0800 Subject: [PATCH 257/454] tests: correctly mount the root and also the boot partitions for Fedora 35, 36 and rawhide Cloud Base Image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fedora 33 and 34 Cloud Base Images have only one partition with the following directory structure, . ├── bin -> usr/bin ├── boot ├── dev ├── etc ├── home ├── root By comparison, Fedora 35, 36 and 37 Cloud Base Images have multiple partitions. The root partition which is the last partition has the following directory, . ├── home └── root ├── bin -> usr/bin ├── boot ├── dev ├── etc ├── home ├── root and the 2nd partition is the boot partition. This patch address the above changes by mounting {LAST_PARTITION}/root as to TEMP_ROOT and mount SECOND_PARTITION to TEMP_ROOT/boot. So the test image can be built successfully. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- tests/scripts/image-init-lib.sh | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/scripts/image-init-lib.sh b/tests/scripts/image-init-lib.sh index 0a1524b..822d740 100644 --- a/tests/scripts/image-init-lib.sh +++ b/tests/scripts/image-init-lib.sh @@ -23,7 +23,7 @@ is_mounted() clean_up() { for _mnt in ${MNTS[@]}; do - is_mounted $_mnt && $SUDO umount -f $_mnt + is_mounted $_mnt && $SUDO umount -f -R $_mnt done for _dev in ${DEVS[@]}; do @@ -81,6 +81,17 @@ get_mountable_dev() { fi } +# get the separate boot partition +# return the 2nd partition as boot partition +get_mount_boot() { + local dev=$1 _second_part=${dev}p2 + + if [[ $(lsblk -f $_second_part -n -o LABEL 2> /dev/null) == boot ]]; then + echo $_second_part + fi +} + + prepare_loop() { [ -n "$(lsmod | grep "^loop")" ] && return @@ -133,7 +144,7 @@ image_lock() # Mount a device, will umount it automatially when shell exits mount_image() { local image=$1 fmt - local dev mnt mnt_dev + local dev mnt mnt_dev boot root # Lock the image just in case user run this script in parrel image_lock $image @@ -166,12 +177,20 @@ mount_image() { $SUDO mount $mnt_dev $mnt [ $? -ne 0 ] && perror_exit "failed to mount device '$mnt_dev'" + boot=$(get_mount_boot "$dev") + if [[ -n "$boot" ]]; then + root=$(get_image_mount_root $image) + $SUDO mount $boot $root/boot + [ $? -ne 0 ] && perror_exit "failed to mount the bootable partition for device '$mnt_dev'" + fi } get_image_mount_root() { local image=$1 local root=${MNTS[$image]} + # Starting from Fedora 36, the root node is /root/root of the last partition + [ -d "$root/root/root" ] && root=$root/root echo $root if [ -z "$root" ]; then @@ -213,7 +232,7 @@ run_in_image() { inst_in_image() { local image=$1 src=$2 dst=$3 - local root=${MNTS[$image]} + local root=$(get_image_mount_root $1) $SUDO cp $src $root/$dst } From f91711ba8e7eb24882c7bd78e7aec85f51727f63 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 29 Apr 2022 14:21:38 +0800 Subject: [PATCH 258/454] tests: specify the backing format for the backing file when using qemu-img create New version of qemu-img requires specifying the backing format for the backing file otherwise it will abort. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- tests/scripts/image-init-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/scripts/image-init-lib.sh b/tests/scripts/image-init-lib.sh index 822d740..467f32f 100644 --- a/tests/scripts/image-init-lib.sh +++ b/tests/scripts/image-init-lib.sh @@ -259,7 +259,7 @@ create_image_from_base_image() { if [ "$image_fmt" != "raw" ]; then if fmt_is_qcow2 "$image_fmt"; then echo "Source image is qcow2, using snapshot..." - qemu-img create -f qcow2 -b $image $output + qemu-img create -f qcow2 -b $image -F qcow2 $output else perror_exit "Unrecognized base image format '$image_mnt'" fi From 2d5df7a512ff0ce2925d08659005a8f7b4deb08f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 29 Apr 2022 14:24:52 +0800 Subject: [PATCH 259/454] tests: specify the Fedora version when running fedpkg sources So fedpkg will fetch the sources that matches given Fedora version. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 8fb38c7..05fda1d 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -42,7 +42,7 @@ all: $(TEST_ROOT)/output/test-base-image # to rebuild the rpm, currently use rpmbuild to have better control over the rpm building process # $(KEXEC_TOOLS_RPM): $(KEXEC_TOOLS_SRC) - sh -c "cd .. && fedpkg sources" + sh -c "cd .. && fedpkg --release f$(RELEASE) sources" @echo Rebuilding RPM due to modification of sources: $? rpmbuild $(RPMDEFINE) -ba $(REPO)/$(SPEC) From aa842443462d588b825c8cbfd5c2112695ddf549 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 3 Aug 2022 19:54:42 +0800 Subject: [PATCH 260/454] Release 2.0.25-1 Signed-off-by: Coiby Xu --- kexec-tools.spec | 13 +++++++++++-- sources | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index c82bea8..24c616d 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,8 +4,8 @@ %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools -Version: 2.0.24 -Release: 4%{?dist} +Version: 2.0.25 +Release: 1%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -416,6 +416,15 @@ fi %endif %changelog +* Wed Aug 03 2022 Coiby - 2.0.25-1 +- Update kexec-tools to 2.0.25 +- remind the users to run zipl after calling grubby on s390x +- remove useless --zipl when calling grubby to update kernel command line +- skip updating /etc/default/grub for s390x +- use /run/ostree-booted to tell if scriptlet is running on OSTree system +- Allow to update kexec-tools using virt-customize for cloud base image +- KDUMP_COMMANDLINE: remove irqpoll parameter on aws aarch64 platform + * Thu Jul 21 2022 Coiby - 2.0.24-4 - Checking the existence of 40-redhat.rules before modifying - kdump-lib: Add the CoreOS kernel dir to the boot_dirlist diff --git a/sources b/sources index d0190bb..15c98ee 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 -SHA512 (kexec-tools-2.0.24.tar.xz) = ef7cf78246e2d729d81a3649791a5a23c385353cc75cbe8ef279616329fdaccc876d614c7f51e1456822a13a11520296070d9897467d24310399909e049c3822 +SHA512 (kexec-tools-2.0.25.tar.xz) = 6fd3fe11d428c5bb2ce318744146e03ddf752cc77632064bdd7418ef3ad355ad2e2db212d68a5bc73554d78f786901beb42d72bd62e2a4dae34fb224b667ec6b SHA512 (makedumpfile-1.7.1.tar.gz) = 93e36487b71f567d3685b151459806cf36017e52bf3ee68dd448382b279a422d1a8abef72e291ccb8206f2149ccd08ba484ec0027d1caab3fa1edbc3d28c3632 From 677da8a59bdf00c661bc6e05c96f2b59a99cfb63 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Mon, 1 Aug 2022 23:25:48 +0800 Subject: [PATCH 261/454] sysconfig: use a simple generator script to maintain These kdump.sysconfig.* files are almost identical with a bit difference in several parameters, just use a simple script to generate them upon packaging. This should make it easier to maintain, updating a comment or param for a certain arch can be done in one place. There are only some comment or empty option differences with the generated version because some arch's sysconfig is not up-to-dated, this actually fixes the issue, I used the following script to check these differences: # for arch in aarch64 i386 ppc64 ppc64le s390x x86_64; do ./gen-kdump-sysconfig.sh $arch > kdump.sysconfig.$arch.new git checkout HEAD^ kdump.sysconfig.$arch &>/dev/null echo "$arch:" diff kdump.sysconfig.$arch kdump.sysconfig.$arch.new; echo "" done; git reset; Signed-off-by: Kairui Song Reviewed-by: Philipp Rudo --- kdump.sysconfig => gen-kdump-sysconfig.sh | 61 +++++++++++++++++++++++ kdump.sysconfig.aarch64 | 53 -------------------- kdump.sysconfig.i386 | 56 --------------------- kdump.sysconfig.ppc64 | 58 --------------------- kdump.sysconfig.ppc64le | 58 --------------------- kdump.sysconfig.s390x | 59 ---------------------- kdump.sysconfig.x86_64 | 56 --------------------- kexec-tools.spec | 17 ++----- 8 files changed, 66 insertions(+), 352 deletions(-) rename kdump.sysconfig => gen-kdump-sysconfig.sh (50%) mode change 100644 => 100755 delete mode 100644 kdump.sysconfig.aarch64 delete mode 100644 kdump.sysconfig.i386 delete mode 100644 kdump.sysconfig.ppc64 delete mode 100644 kdump.sysconfig.ppc64le delete mode 100644 kdump.sysconfig.s390x delete mode 100644 kdump.sysconfig.x86_64 diff --git a/kdump.sysconfig b/gen-kdump-sysconfig.sh old mode 100644 new mode 100755 similarity index 50% rename from kdump.sysconfig rename to gen-kdump-sysconfig.sh index c1143f3..bc37dee --- a/kdump.sysconfig +++ b/gen-kdump-sysconfig.sh @@ -1,3 +1,11 @@ +#!/bin/bash +# $1: target arch + +SED_EXP="" + +generate() +{ + sed "$SED_EXP" << EOF # Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump # If no version is specified, then the init script will try to find a # kdump kernel with the same version number as the running kernel. @@ -36,6 +44,9 @@ KEXEC_ARGS="" #What is the image type used for kdump KDUMP_IMG="vmlinuz" +#What is the images extension. Relocatable kernels don't have one +KDUMP_IMG_EXT="" + # 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) @@ -51,3 +62,53 @@ KDUMP_IMG="vmlinuz" # KDUMP_STDLOGLVL=3 # KDUMP_SYSLOGLVL=0 # KDUMP_KMSGLOGLVL=0 +EOF +} + +update_param() +{ + SED_EXP="${SED_EXP}s/^$1=.*$/$1=\"$2\"/;" +} + +case "$1" in +aarch64) + update_param KEXEC_ARGS "-s" + update_param KDUMP_COMMANDLINE_APPEND \ + "irqpoll nr_cpus=1 reset_devices cgroup_disable=memory udev.children-max=2 panic=10 swiotlb=noforce novmcoredd cma=0 hugetlb_cma=0" + ;; +i386) + update_param KDUMP_COMMANDLINE_APPEND \ + "irqpoll nr_cpus=1 reset_devices numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd cma=0 hugetlb_cma=0" + ;; +ppc64) + update_param KEXEC_ARGS "--dt-no-old-root" + update_param KDUMP_COMMANDLINE_REMOVE \ + "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" + update_param KDUMP_COMMANDLINE_APPEND \ + "irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" + ;; +ppc64le) + update_param KEXEC_ARGS "--dt-no-old-root -s" + update_param KDUMP_COMMANDLINE_REMOVE \ + "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" + update_param KDUMP_COMMANDLINE_APPEND \ + "irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" + ;; +s390x) + update_param KEXEC_ARGS "-s" + update_param KDUMP_COMMANDLINE_REMOVE \ + "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt ignition.firstboot" + update_param KDUMP_COMMANDLINE_APPEND \ + "nr_cpus=1 cgroup_disable=memory numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd vmcp_cma=0 cma=0 hugetlb_cma=0" + ;; +x86_64) + update_param KEXEC_ARGS "-s" + update_param 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 cma=0 hugetlb_cma=0" + ;; +*) + echo "Warning: Unknown architecture '$1', using default sysconfig template." + ;; +esac + +generate diff --git a/kdump.sysconfig.aarch64 b/kdump.sysconfig.aarch64 deleted file mode 100644 index df75f94..0000000 --- a/kdump.sysconfig.aarch64 +++ /dev/null @@ -1,53 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory udev.children-max=2 panic=10 swiotlb=noforce novmcoredd cma=0 hugetlb_cma=0" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="-s" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -# 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) -# -# 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 -# -# 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 deleted file mode 100644 index d8bf5f6..0000000 --- a/kdump.sysconfig.i386 +++ /dev/null @@ -1,56 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd cma=0 hugetlb_cma=0" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" - -# 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) -# -# 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 -# -# 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 deleted file mode 100644 index 1b0cdc7..0000000 --- a/kdump.sysconfig.ppc64 +++ /dev/null @@ -1,58 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="--dt-no-old-root" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" - -#Specify the action after failure - -# 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) -# -# 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 -# -# 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 deleted file mode 100644 index d951def..0000000 --- a/kdump.sysconfig.ppc64le +++ /dev/null @@ -1,58 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="--dt-no-old-root -s" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" - -#Specify the action after failure - -# 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) -# -# 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 -# -# 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 deleted file mode 100644 index 2971ae7..0000000 --- a/kdump.sysconfig.s390x +++ /dev/null @@ -1,59 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt ignition.firstboot" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="nr_cpus=1 cgroup_disable=memory numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd vmcp_cma=0 cma=0 hugetlb_cma=0" - -# Any additional /sbin/mkdumprd arguments required. -MKDUMPRD_ARGS="" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="-s" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" - -# 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) -# -# 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 -# -# 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 deleted file mode 100644 index 6a3ba6e..0000000 --- a/kdump.sysconfig.x86_64 +++ /dev/null @@ -1,56 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -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 cma=0 hugetlb_cma=0" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="-s" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" - -# 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) -# -# 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 -# -# 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/kexec-tools.spec b/kexec-tools.spec index 24c616d..ee43b13 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -11,10 +11,7 @@ Summary: The kexec/kdump userspace component Source0: http://kernel.org/pub/linux/utils/kernel/kexec/%{name}-%{version}.tar.xz Source1: kdumpctl -Source2: kdump.sysconfig -Source3: kdump.sysconfig.x86_64 -Source4: kdump.sysconfig.i386 -Source5: kdump.sysconfig.ppc64 +Source3: gen-kdump-sysconfig.sh Source7: mkdumprd Source8: kdump.conf Source9: https://github.com/makedumpfile/makedumpfile/archive/%{mkdf_ver}/makedumpfile-%{mkdf_shortver}.tar.gz @@ -25,18 +22,15 @@ Source13: 98-kexec.rules Source14: 98-kexec.rules.ppc64 Source15: kdump.conf.5 Source16: kdump.service -Source18: kdump.sysconfig.s390x Source19: https://github.com/lucchouina/eppic/archive/%{eppic_ver}/eppic-%{eppic_shortver}.tar.gz Source20: kdump-lib.sh Source21: kdump-in-cluster-environment.txt Source22: kdump-dep-generator.sh Source23: kdump-lib-initramfs.sh -Source24: kdump.sysconfig.ppc64le Source25: kdumpctl.8 Source26: live-image-kdump-howto.txt Source27: early-kdump-howto.txt Source28: kdump-udev-throttler -Source29: kdump.sysconfig.aarch64 Source30: 60-kdump.install Source31: kdump-logger.sh Source32: mkfadumprd @@ -152,6 +146,9 @@ cp %{SOURCE26} . cp %{SOURCE27} . cp %{SOURCE34} . +# Generate sysconfig file +%{SOURCE3} %{_target_cpu} > kdump.sysconfig + make %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 make -C eppic-%{eppic_ver}/libeppic @@ -183,13 +180,9 @@ install -m 755 build/sbin/vmcore-dmesg $RPM_BUILD_ROOT/usr/sbin/vmcore-dmesg install -m 644 build/man/man8/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/ install -m 644 build/man/man8/vmcore-dmesg.8 $RPM_BUILD_ROOT%{_mandir}/man8/ -SYSCONFIG=$RPM_SOURCE_DIR/kdump.sysconfig.%{_target_cpu} -[ -f $SYSCONFIG ] || SYSCONFIG=$RPM_SOURCE_DIR/kdump.sysconfig.%{_arch} -[ -f $SYSCONFIG ] || SYSCONFIG=$RPM_SOURCE_DIR/kdump.sysconfig -install -m 644 $SYSCONFIG $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/kdump - install -m 755 %{SOURCE7} $RPM_BUILD_ROOT/usr/sbin/mkdumprd install -m 644 %{SOURCE8} $RPM_BUILD_ROOT%{_sysconfdir}/kdump.conf +install -m 644 kdump.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/kdump install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8 install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8 install -m 644 %{SOURCE25} $RPM_BUILD_ROOT%{_mandir}/man8/kdumpctl.8 From 4edcd9a4001f684d6c5b66afc2e164bdd6a296eb Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Wed, 24 Aug 2022 16:16:14 +0800 Subject: [PATCH 262/454] kdumpctl: make the kdump.log root-readable-only Decrease the risk that of leaking information that could potentially be used to exploit the crash further (think location of keys). Signed-off-by: Lichen Liu Acked-by: Coiby Xu --- kdumpctl | 1 + 1 file changed, 1 insertion(+) diff --git a/kdumpctl b/kdumpctl index 126ecb9..0e37d36 100755 --- a/kdumpctl +++ b/kdumpctl @@ -691,6 +691,7 @@ load_kdump() # and release it. exec 12>&2 exec 2>> $KDUMP_LOG_PATH/kdump.log + chmod 600 $KDUMP_LOG_PATH/kdump.log PS4='+ $(date "+%Y-%m-%d %H:%M:%S") ${BASH_SOURCE}@${LINENO}: ' set -x From 4d52b7d5480ae27bfe70a55030b3be1282843662 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Tue, 6 Sep 2022 11:15:15 +0800 Subject: [PATCH 263/454] mkdumprd: Improve error messages on non-existing NFS target directories When kdump is configured with a NFS location, and the remote directory does not exist, kdump.service fails with a confusing error message. kdumpctl[2172]: kdump: Dump path "/tmp/mkdumprd.ftWhOF/target/dumps" does not exist in dump target "10.111.113.2:/srv/kdump" We just need to print the remote directory "dumps" in such case, because "/tmp/mkdumprd.ftWhOF/target" is the local temporary mount point. Signed-off-by: Lichen Liu Reviewed-by: Coiby Xu --- mkdumprd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdumprd b/mkdumprd index 3e250e0..c0f131d 100644 --- a/mkdumprd +++ b/mkdumprd @@ -242,7 +242,7 @@ check_user_configured_target() # For user configured target, use $SAVE_PATH as the dump path within the target if [[ ! -d "$_mnt/$SAVE_PATH" ]]; then - perror_exit "Dump path \"$_mnt/$SAVE_PATH\" does not exist in dump target \"$_target\"" + perror_exit "Dump path \"$SAVE_PATH\" does not exist in dump target \"$_target\"" fi check_size fs "$_target" From d905d49c08deab9a404220e8dc0c127df51455d2 Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Fri, 16 Sep 2022 19:07:24 +0530 Subject: [PATCH 264/454] fadump: avoid non-debug kernel use for fadump case Since commit c5bdd2d8f195 ("kdump-lib: use non-debug kernels first"), non-debug kernel is preferred, over the debug variant, as dump capture kernel to reduce memory consumption. This works alright for kdump as the capture kernel is loaded using kexec. In case of fadump, regular boot loader is used to load the capture kernel. So, the default kernel needs to be used as capture kernel as well. But with commit c5bdd2d8f195, initrd of a different kernel is made dump capture capable, breaking fadump's ability to capture dump properly. Fix this by sticking with the debug variant in case of fadump. Fixes: c5bdd2d8f195 ("kdump-lib: use non-debug kernels first") Signed-off-by: Hari Bathini Acked-by: Lichen Liu Acked-by: Coiby Xu --- kdump-lib.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index f7b659e..6d081a8 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -680,7 +680,13 @@ prepare_kdump_bootinfo() if [[ -z $KDUMP_KERNELVER ]]; then KDUMP_KERNELVER=$(uname -r) - nondebug_kernelver=$(sed -n -e 's/\(.*\)+debug$/\1/p' <<< "$KDUMP_KERNELVER") + + # Fadump uses the regular bootloader, unlike kdump. So, use the same version + # for default kernel and capture kernel unless specified explicitly with + # KDUMP_KERNELVER option. + if ! is_fadump_capable; then + nondebug_kernelver=$(sed -n -e 's/\(.*\)+debug$/\1/p' <<< "$KDUMP_KERNELVER") + fi fi # Use nondebug kernel if possible, because debug kernel will consume more memory and may oom. From c743881ae691c4e2bcf049cbf28abd2850b816e8 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Fri, 23 Sep 2022 18:13:11 +0800 Subject: [PATCH 265/454] virtiofs support for kexec-tools This patch add virtiofs support for kexec-tools by introducing a new option for /etc/kdump.conf: virtiofs myfs Where myfs is a variable tag name specified in qemu cmdline "-device vhost-user-fs-pci,tag=myfs". The patch covers the following cases: 1) Dumping VM's vmcore to a virtiofs shared directory; 2) When the VM's rootfs is a virtiofs shared directory and dumping the VM's vmcore to its subdirectory, such as /var/crash; 3) The combination of case 1 & 2: The VM's rootfs is a virtiofs shared directory and dumping the VM's vmcore to another virtiofs shared directory. Case 2 & 3 need dracut >= 057, otherwise VM cannot boot from virtiofs shared rootfs. But it is not the issue of kexec-tools. Reviewed-by: Philipp Rudo Signed-off-by: Tao Liu --- dracut-kdump.sh | 2 +- dracut-module-setup.sh | 2 +- kdump-lib-initramfs.sh | 24 +++++++++++++++++++++++- kdump-lib.sh | 33 +++++++++++++++------------------ kdump.conf | 2 ++ kdumpctl | 6 +++--- mkdumprd | 2 +- 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index f4456a1..5c980a8 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -519,7 +519,7 @@ read_kdump_confs() DUMP_INSTRUCTION="dump_fs $config_val" fi ;; - ext[234] | xfs | btrfs | minix | nfs) + ext[234] | xfs | btrfs | minix | nfs | virtiofs) config_val=$(get_mntpoint_from_target "$config_val") DUMP_INSTRUCTION="dump_fs $config_val" ;; diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 4c6096a..a790a93 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -673,7 +673,7 @@ kdump_install_conf() { _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val") sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" ;; - ext[234] | xfs | btrfs | minix) + ext[234] | xfs | btrfs | minix | virtiofs) _pdev=$(kdump_get_persistent_dev "$_val") sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" ;; diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 84e6bf7..e982b14 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -55,6 +55,11 @@ is_fs_type_nfs() [ "$1" = "nfs" ] || [ "$1" = "nfs4" ] } +is_fs_type_virtiofs() +{ + [ "$1" = "virtiofs" ] +} + # If $1 contains dracut_args "--mount", return get_dracut_args_fstype() { @@ -110,6 +115,23 @@ is_raw_dump_target() [ -n "$(kdump_get_conf_val raw)" ] } +is_virtiofs_dump_target() +{ + if [ -n "$(kdump_get_conf_val virtiofs)" ]; then + return 0 + fi + + if is_fs_type_virtiofs "$(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)")"; then + return 0 + fi + + if is_fs_type_virtiofs "$(get_fs_type_from_target "$(get_target_from_path "$(get_save_path)")")"; then + return 0 + fi + + return 1 +} + is_nfs_dump_target() { if [ -n "$(kdump_get_conf_val nfs)" ]; then @@ -129,5 +151,5 @@ is_nfs_dump_target() is_fs_dump_target() { - [ -n "$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix")" ] + [ -n "$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|virtiofs")" ] } diff --git a/kdump-lib.sh b/kdump-lib.sh index 6d081a8..817652d 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -81,35 +81,31 @@ to_dev_name() is_user_configured_dump_target() { - [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh") ]] || is_mount_in_dracut_args -} - -get_user_configured_dump_disk() -{ - local _target - - _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw") - [[ -n $_target ]] && echo "$_target" && return - - _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") - [[ -b $_target ]] && echo "$_target" + [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh\|virtiofs") ]] || is_mount_in_dracut_args } get_block_dump_target() { - local _target _path + local _target _fstype if is_ssh_dump_target || is_nfs_dump_target; then return fi - _target=$(get_user_configured_dump_disk) + _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|virtiofs") [[ -n $_target ]] && to_dev_name "$_target" && return - # Get block device name from local save path - _path=$(get_save_path) - _target=$(get_target_from_path "$_path") - [[ -b $_target ]] && to_dev_name "$_target" + _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") + [[ -b $_target ]] && to_dev_name "$_target" && return + + _fstype=$(get_dracut_args_fstype "$(kdump_get_conf_val "dracut_args")") + is_fs_type_virtiofs "$_fstype" && echo "$_target" && return + + _target=$(get_target_from_path "$(get_save_path)") + [[ -b $_target ]] && to_dev_name "$_target" && return + + _fstype=$(get_fs_type_from_target "$_target") + is_fs_type_virtiofs "$_fstype" && echo "$_target" && return } is_dump_to_rootfs() @@ -125,6 +121,7 @@ get_failure_action_target() # Get rootfs device name _target=$(get_root_fs_device) [[ -b $_target ]] && to_dev_name "$_target" && return + is_fs_type_virtiofs "$(get_fs_type_from_target "$_target")" && echo "$_target" && return # Then, must be nfs root echo "nfs" fi diff --git a/kdump.conf b/kdump.conf index d4fc78b..e598a49 100644 --- a/kdump.conf +++ b/kdump.conf @@ -43,6 +43,7 @@ # It's recommended to use persistent device names # such as /dev/vg/. # Otherwise it's suggested to use label or uuid. +# Supported fs types: ext[234], xfs, btrfs, minix, virtiofs # # path # - "path" represents the file system path in which vmcore @@ -171,6 +172,7 @@ #ext4 /dev/vg/lv_kdump #ext4 LABEL=/boot #ext4 UUID=03138356-5e61-4ab3-b58e-27507ac41937 +#virtiofs myfs #nfs my.server.com:/export/tmp #nfs [2001:db8::1:2:3:4]:/export/tmp #ssh user@my.server.com diff --git a/kdumpctl b/kdumpctl index 0e37d36..c7efa2c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -239,7 +239,7 @@ parse_config() _set_config _fstype "$config_opt" || return 1 config_opt=_target ;; - ext[234] | minix | btrfs | xfs | nfs | ssh) + ext[234] | minix | btrfs | xfs | nfs | ssh | virtiofs) _set_config _fstype "$config_opt" || return 1 config_opt=_target ;; @@ -478,8 +478,8 @@ check_fs_modified() fi # No need to check in case of raw target. - # Currently we do not check also if ssh/nfs target is specified - if is_ssh_dump_target || is_nfs_dump_target || is_raw_dump_target; then + # Currently we do not check also if ssh/nfs/virtiofs target is specified + if is_ssh_dump_target || is_nfs_dump_target || is_raw_dump_target || is_virtiofs_dump_target; then return 0 fi diff --git a/mkdumprd b/mkdumprd index c0f131d..2e5659d 100644 --- a/mkdumprd +++ b/mkdumprd @@ -391,7 +391,7 @@ while read -r config_opt config_val; do extra_modules) extra_modules="$extra_modules $config_val" ;; - ext[234] | xfs | btrfs | minix | nfs) + ext[234] | xfs | btrfs | minix | nfs | virtiofs) check_user_configured_target "$config_val" "$config_opt" add_mount "$config_val" "$config_opt" ;; From bea61431785def6a10aaf55b4c15657d9ad0ca32 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 8 Oct 2022 14:53:21 +0800 Subject: [PATCH 266/454] Fix the sync issue for dump_fs Previously the sync for dump_fs is problematic, it always return success according to man 2 sync. So it cannot detect the error of the dump target is full and not all of vmcore data been written back the disk, which will leave the vmcore imcomplete and report misleading log as "saving vmcore complete". In this patch, we will use "sync -f vmcore" instead, which will return error if syncfs on the dump target fails. In this way, vmcore sync related failures, such as autoextend of lvm2 thinpool fails, can be detected and handled properly. Signed-off-by: Tao Liu Reviewed-by: Coiby Xu --- dracut-kdump.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 5c980a8..9734f43 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -174,9 +174,15 @@ dump_fs() $CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete" _dump_exitcode=$? if [ $_dump_exitcode -eq 0 ]; then - mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore" - sync - dinfo "saving vmcore complete" + sync -f "$_dump_fs_path/vmcore-incomplete" + _sync_exitcode=$? + if [ $_sync_exitcode -eq 0 ]; then + mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore" + dinfo "saving vmcore complete" + else + derror "sync vmcore failed, exitcode:$_sync_exitcode" + return 1 + fi else derror "saving vmcore failed, exitcode:$_dump_exitcode" return 1 From fc1c79ffd21e7bcb3a710368cd7023c9a634258e Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 8 Oct 2022 12:09:08 +0800 Subject: [PATCH 267/454] Seperate dracut and dracut-squash compressor for zstd Previously kexec-tools will pass "--compress zstd" to dracut. It will make dracut to decide whether: a) call mksquashfs to make a zstd format squash-root.img, b) call cmd zstd to make a initramfs. Since dracut(>= 057) has decoupled the compressor for dracut and dracut-squash, So in this patch, we will pass the compressor seperately. Note: The is_squash_available && !dracut_has_option --squash-compressor && !is_zsdt_command_available case is left unprocessed on purpose. Actually, the situation when we want to call zstd compression is: 1) If squash function OK, we want dracut to invoke mksquashfs to make a zstd format squash-root.img within initramfs. 2) If squash function is not OK, and cmd zstd presents, we want dracut to invoke cmd zstd to make a zstd format initramfs. is_zstd_command_available check can handle case 2 completely. However, for the is_squash_available check, it cannot handle case 1 completely. It only checks if the kernel supports squashfs, it doesn't check whether the squash module has been added by dracut when making initramfs. In fact, in kexec-tools we are unable to do the check, there are multiple ways to forbit dracut to load a module, such as "dracut -o module" and "omit_dracutmodules in dracut.conf". When squash dracut module is omitted, is_squash_available check will still pass, so "--compress zstd" will be appended to dracut cmdline, and it will call cmd zstd to do the compression. However cmd zstd may not exist, so it fails. The previous "--compress zstd" is ambiguous, after the intro of "--squash-compressor", "--squash-compressor" only effect for mksquashfs and "--compress" only effect for specific cmd. So for the is_squash_available && !dracut_has_option --squash-compressor && !is_zsdt_command_available case, we just leave it to be handled the default way. Reviewed-by: Philipp Rudo Signed-off-by: Tao Liu --- kdump-lib.sh | 9 +++++++-- kexec-tools.spec | 1 - mkdumprd | 7 +++---- mkfadumprd | 4 +++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 817652d..b50b4f4 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -37,6 +37,12 @@ is_zstd_command_available() [[ -x "$(command -v zstd)" ]] } +dracut_have_option() +{ + local _option=$1 + ! dracut "$_option" 2>&1 | grep -q "unrecognized option" +} + perror_exit() { derror "$@" @@ -448,8 +454,7 @@ is_wdt_active() have_compression_in_dracut_args() { - [[ "$(kdump_get_conf_val dracut_args)" =~ \ - (^|[[:space:]])--(gzip|bzip2|lzma|xz|lzo|lz4|zstd|no-compress|compress)([[:space:]]|$) ]] + [[ "$(kdump_get_conf_val dracut_args)" =~ (^|[[:space:]])--(gzip|bzip2|lzma|xz|lzo|lz4|zstd|no-compress|compress|squash-compressor)([[:space:]]|$) ]] } # If "dracut_args" contains "--mount" information, use it diff --git a/kexec-tools.spec b/kexec-tools.spec index ee43b13..c829bbe 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -64,7 +64,6 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool -Recommends: zstd Recommends: grubby Recommends: hostname BuildRequires: make diff --git a/mkdumprd b/mkdumprd index 2e5659d..7b843a8 100644 --- a/mkdumprd +++ b/mkdumprd @@ -432,10 +432,9 @@ done <<< "$(kdump_read_conf)" handle_default_dump_target if ! have_compression_in_dracut_args; then - # Here zstd is set as the default compression method. If squash module - # is available for dracut, libzstd will be used by mksquashfs. If - # squash module is unavailable, command zstd will be used instead. - if is_squash_available || is_zstd_command_available; then + if is_squash_available && dracut_have_option "--squash-compressor"; then + add_dracut_arg "--squash-compressor" "zstd" + elif is_zstd_command_available; then add_dracut_arg "--compress" "zstd" fi fi diff --git a/mkfadumprd b/mkfadumprd index 86dfcee..f353f15 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -64,7 +64,9 @@ fi # Same as setting zstd in mkdumprd if ! have_compression_in_dracut_args; then - if is_squash_available || is_zstd_command_available; then + if is_squash_available && dracut_have_option "--squash-compressor"; then + _dracut_isolate_args+=(--squash-compressor zstd) + elif is_zstd_command_available; then _dracut_isolate_args+=(--compress zstd) fi fi From a7ead187a4694188de2e8ee26f8063fcec310085 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 8 Sep 2022 14:08:42 +0800 Subject: [PATCH 268/454] Prefix reset-crashkernel-{for-installed_kernel,after-update} with underscore Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2048690 To indicate they are for internal use only, underscore them. Reported-by: rcheerla@redhat.com Signed-off-by: Coiby Xu Reviewed-by: Lichen Liu --- 92-crashkernel.install | 2 +- kdumpctl | 4 ++-- kexec-tools.spec | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/92-crashkernel.install b/92-crashkernel.install index 1d67a13..19bd078 100755 --- a/92-crashkernel.install +++ b/92-crashkernel.install @@ -7,7 +7,7 @@ KERNEL_IMAGE="$4" case "$COMMAND" in add) - kdumpctl reset-crashkernel-for-installed_kernel "$KERNEL_VERSION" + kdumpctl _reset-crashkernel-for-installed_kernel "$KERNEL_VERSION" exit 0 ;; esac diff --git a/kdumpctl b/kdumpctl index c7efa2c..690584e 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1764,12 +1764,12 @@ main() shift reset_crashkernel "$@" ;; - reset-crashkernel-after-update) + _reset-crashkernel-after-update) if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then reset_crashkernel_after_update fi ;; - reset-crashkernel-for-installed_kernel) + _reset-crashkernel-for-installed_kernel) if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then reset_crashkernel_for_installed_kernel "$2" fi diff --git a/kexec-tools.spec b/kexec-tools.spec index c829bbe..ba9f0ea 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -342,7 +342,7 @@ done # 2. "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade. The # former case is used to set up crashkernel for osbuild if [ ! -f /run/ostree-booted ] && [ $1 == 1 ]; then - kdumpctl reset-crashkernel-after-update + kdumpctl _reset-crashkernel-after-update rm /tmp/old_default_crashkernel 2>/dev/null %ifarch ppc64 ppc64le rm /tmp/old_default_crashkernel_fadump 2>/dev/null From e218128e282066440a4a654707309d785066d79a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 8 Sep 2022 14:30:02 +0800 Subject: [PATCH 269/454] Only try to reset crashkernel for osbuild during package install Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2060319 Currently, kexec-tools tries to reset crashkernel when using anaconda to install the system. But grubby isn't ready and complains that, 10:33:17,631 INF packaging: Configuring (running scriptlet for): kernel-core-5.14.0-70.el9.x86_64 1645746534 03dcd32db234b72440ee6764d59b32347c5f0cd98ac3fb55beb47214a76f33b4 10:34:16,696 INF dnf.rpm: grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory We only need to try resetting crashkernel for osbuild. Skip it for other cases. To tell if it's package install instead of package upgrade, make use of %pre to write a file /tmp/kexec-tools-install when "$1 == 1" [1]. [1] https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax Reported-by: Jan Stodola Signed-off-by: Coiby Xu Reviewed-by: Lichen Liu --- kdumpctl | 16 ++++++++++++++++ kexec-tools.spec | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/kdumpctl b/kdumpctl index 690584e..7f82f4f 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1597,6 +1597,12 @@ reset_crashkernel() fi } +# to tell if it's package install other than upgrade +_is_package_install() +{ + [[ -f /tmp/kexec_tools_package_install ]] +} + # update the crashkernel value in GRUB_ETC_DEFAULT if necessary # # called by reset_crashkernel_after_update and inherit its array variable @@ -1606,6 +1612,10 @@ update_crashkernel_in_grub_etc_default_after_update() local _crashkernel _fadump_val local _dump_mode _old_default_crashkernel _new_default_crashkernel + if _is_package_install; then + return + fi + _crashkernel=$(_read_kernel_arg_in_grub_etc_default crashkernel) if [[ -z $_crashkernel ]]; then @@ -1681,6 +1691,12 @@ reset_crashkernel_for_installed_kernel() local _installed_kernel _running_kernel _crashkernel _crashkernel_running local _dump_mode_running _fadump_val_running + # During package install, only try to reset crashkernel for osbuild + # thus to avoid calling grubby when installing os via anaconda + if _is_package_install && ! _is_osbuild; then + return + fi + if ! _installed_kernel=$(_find_kernel_path_by_release "$1"); then exit 1 fi diff --git a/kexec-tools.spec b/kexec-tools.spec index ba9f0ea..c9c1ce7 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -265,6 +265,11 @@ if [ ! -f /run/ostree-booted ] && [ $1 == 2 ] && grep -q get-default-crashkernel kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null %endif fi +# indicate it's package install so kdumpctl later will only reset crashkernel +# value for osbuild. +if [ $1 == 1 ]; then + touch /tmp/kexec_tools_package_install +fi # don't block package update : From 15122b3f983f3cbb2ea47c2fbe1121681928f988 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 20 Sep 2022 17:09:44 +0800 Subject: [PATCH 270/454] Fix grep warnings "grep: warning: stray \ before -" Latest grep (3.8) warnings about unneeded backslashes when building kdump initrd [1], kdump: Rebuilding /boot/initramfs-6.0.0-0.rc5.a335366bad13.40.test.fc38.aarch64kdump.img grep: warning: stray \ before - grep: warning: stray \ before - grep: warning: stray \ before - grep: warning: stray \ before - grep: warning: stray \ before - Some warnings can be avoided by using "sed -n" to remove grep and the others can use the -- argument. [1] https://s3.us-east-1.amazonaws.com/arr-cki-prod-datawarehouse-public/datawarehouse-public/2022/09/17/redhat:643020269/build_aarch64_redhat:643020269_aarch64/tests/4/results_0001/job.01/recipes/12617739/tasks/5/logs/taskout.log Reported-by: Baoquan He Signed-off-by: Coiby Xu Suggested-by: Philipp Rudo Reviewed-by: Philipp Rudo --- kdump-lib-initramfs.sh | 4 ++-- kdumpctl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index e982b14..52dfcb4 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -63,13 +63,13 @@ is_fs_type_virtiofs() # If $1 contains dracut_args "--mount", return get_dracut_args_fstype() { - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f3 + echo "$1" | sed -n "s/.*--mount .\(.*\)/\1/p" | cut -d' ' -f3 } # If $1 contains dracut_args "--mount", return get_dracut_args_target() { - echo $1 | grep "\-\-mount" | sed "s/.*--mount .\(.*\)/\1/" | cut -d' ' -f1 + echo "$1" | sed -n "s/.*--mount .\(.*\)/\1/p" | cut -d' ' -f1 } get_save_path() diff --git a/kdumpctl b/kdumpctl index 7f82f4f..8ff4cb0 100755 --- a/kdumpctl +++ b/kdumpctl @@ -224,7 +224,7 @@ parse_config() case "$config_opt" in dracut_args) if [[ $config_val == *--mount* ]]; then - if [[ $(echo "$config_val" | grep -o "\-\-mount" | wc -l) -ne 1 ]]; then + if [[ $(echo "$config_val" | grep -o -- "--mount" | wc -l) -ne 1 ]]; then derror 'Multiple mount targets specified in one "dracut_args".' return 1 fi @@ -506,7 +506,7 @@ check_fs_modified() # if --mount argument present then match old and new target, mount # point and file system. If any of them mismatches then rebuild - if echo "$_dracut_args" | grep -q "\-\-mount"; then + if echo "$_dracut_args" | grep -q -- "--mount"; then # shellcheck disable=SC2046 set -- $(echo "$_dracut_args" | awk -F "--mount '" '{print $2}' | cut -d' ' -f1,2,3) _old_dev=$1 From 50a8461fc7cc70b57387baa58ff4db864ba36632 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 5 Sep 2022 17:49:18 +0800 Subject: [PATCH 271/454] Choosing the most memory-consuming key slot when estimating the memory requirement for LUKS-encrypted target When there are multiple key slots, "kdumpctl estimate" uses the least memory-consuming key slot. For example, when there are two memory slots created with --pbkdf-memory=1048576 (1G) and --pbkdf-memory=524288 (512M), "kdumpctl estimate" thinks the extra memory requirement is only 512M. This will of course lead to OOM if the user uses the more memory-consuming key slot. Fix it by sorting in reverse order. Fixes: e9e6a2c ("kdumpctl: Add kdumpctl estimate") Signed-off-by: Coiby Xu Reviewed-by: Lichen Liu Signed-off-by: Coiby Xu --- kdumpctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 8ff4cb0..90d84f3 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1242,12 +1242,12 @@ do_estimate() for _dev in $(get_all_kdump_crypt_dev); do _crypt_info=$(cryptsetup luksDump "/dev/block/$_dev") [[ $(echo "$_crypt_info" | sed -n "s/^Version:\s*\(.*\)/\1/p") == "2" ]] || continue - for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n); do + for _mem in $(echo "$_crypt_info" | sed -n "s/\sMemory:\s*\(.*\)/\1/p" | sort -n -r); do crypt_size=$((crypt_size + _mem * 1024)) break done done - [[ $crypt_size -ne 0 ]] && echo -e "Encrypted kdump target requires extra memory, assuming using the keyslot with minimun memory requirement\n" + [[ $crypt_size -ne 0 ]] && echo -e "Encrypted kdump target requires extra memory, assuming using the keyslot with maximum memory requirement\n" estimated_size=$((kernel_size + mod_size + initrd_size + runtime_size + crypt_size)) if [[ $baseline_size -gt $estimated_size ]]; then From 6ce4b85bb3ed6c97beda9ee4774e0924afbbf58a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 5 Sep 2022 18:08:44 +0800 Subject: [PATCH 272/454] Include the memory overhead cost of cryptsetup when estimating the memory requirement for LUKS-encrypted target Currently, "kdumpctl estimate" neglects the memory overhead cost of cryptsetup itself. Unfortunately, there is no golden formula to calculate the overhead cost [1]. So estimate the overhead cost as 50M for aarch64 and 20M for other architectures based on the following empirical data, | Overhead (M) | OS | arch | | ------------ | ----------------------------------------- | ------- | | 14.1 | RHEL-9.2.0-20220829.d.1 | ppc64le | | 14 | Fedora-37-20220830.n.0 Everything ppc64le | ppc64le | | 17 | Fedora 36 | ppc64le | | 8.8 | Fedora 35 | s390x | | 10.1 | Fedora-Rawhide-20220829.n.0, fc38 | s390x | | 42 | Fedora-Rawhide-20220829.n.0, fc38 | arch64 | | 40 | F35 | arch64 | | 42 | F36 | arch64 | | 42 | Fedora-Rawhide-20220901.n.0 | arch64 | | 10 | F35 | x86_64 | | 10 | Fedora-Rawhide-20220901.n.0 | x86_64 | | 11 | Fedora-Rawhide-20220901.n.0 | x86_64 | [1] https://lore.kernel.org/cryptsetup/20220616044339.376qlipk5h2omhx2@Rk/T/#u Fixes: e9e6a2c ("kdumpctl: Add kdumpctl estimate") Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdumpctl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 90d84f3..42c839b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1193,7 +1193,7 @@ do_estimate() local kdump_mods local -A large_mods local baseline - local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommended_size + local kernel_size mod_size initrd_size baseline_size runtime_size reserved_size estimated_size recommended_size _cryptsetup_overhead local size_mb=$((1024 * 1024)) setup_initrd @@ -1247,7 +1247,17 @@ do_estimate() break done done - [[ $crypt_size -ne 0 ]] && echo -e "Encrypted kdump target requires extra memory, assuming using the keyslot with maximum memory requirement\n" + + if [[ $crypt_size -ne 0 ]]; then + if [[ $(uname -m) == aarch64 ]]; then + _cryptsetup_overhead=50 + else + _cryptsetup_overhead=20 + fi + + crypt_size=$((crypt_size + _cryptsetup_overhead * size_mb)) + echo -e "Encrypted kdump target requires extra memory, assuming using the keyslot with maximum memory requirement\n" + fi estimated_size=$((kernel_size + mod_size + initrd_size + runtime_size + crypt_size)) if [[ $baseline_size -gt $estimated_size ]]; then From fdad7d9869a9637e6799cce222d386aed0b8781e Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 29 Sep 2022 12:35:00 +0800 Subject: [PATCH 273/454] Skip reading /etc/defaut/grub for s390x Currently, updating kexec-tools on s390x gives the warning sed: can't read /etc/default/grub: No such file or directory This happens because s390x doesn't use GRUB and /etc/default/grub doesn't exist. We need to skip both reading and writing to /etc/default/grub. Reported-by: Jie Li Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- kdumpctl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kdumpctl b/kdumpctl index 42c839b..d4d196f 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1626,6 +1626,10 @@ update_crashkernel_in_grub_etc_default_after_update() return fi + if [[ $(uname -m) == s390x ]]; then + return + fi + _crashkernel=$(_read_kernel_arg_in_grub_etc_default crashkernel) if [[ -z $_crashkernel ]]; then From 995ee249034e762a29623daece276f27e712e959 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 27 Oct 2022 16:00:11 +0800 Subject: [PATCH 274/454] Release 2.0.25-2 Signed-off-by: Coiby Xu --- kexec-tools.spec | 20 ++++++++++++++++++-- sources | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index c9c1ce7..bfa7a5b 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,11 +1,11 @@ %global eppic_ver e8844d3793471163ae4a56d8f95897be9e5bd554 %global eppic_shortver %(c=%{eppic_ver}; echo ${c:0:7}) -%global mkdf_ver 1.7.1 +%global mkdf_ver 1.7.2 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools Version: 2.0.25 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -413,6 +413,22 @@ fi %endif %changelog +* Thu Oct 27 2022 Coiby - 2.0.25-1 +- Update makedumpfile to 1.7.2 +- Skip reading /etc/defaut/grub for s390x +- Include the memory overhead cost of cryptsetup when estimating the memory requirement for LUKS-encrypted target +- Choosing the most memory-consuming key slot when estimating the memory requirement for LUKS-encrypted target +- Fix grep warnings "grep: warning: stray \ before -" +- Only try to reset crashkernel for osbuild during package install +- Prefix reset-crashkernel-{for-installed_kernel,after-update} with underscore +- Seperate dracut and dracut-squash compressor for zstd +- Fix the sync issue for dump_fs +- virtiofs support for kexec-tools +- fadump: avoid non-debug kernel use for fadump case +- mkdumprd: Improve error messages on non-existing NFS target directories +- kdumpctl: make the kdump.log root-readable-only +- sysconfig: use a simple generator script to maintain + * Wed Aug 03 2022 Coiby - 2.0.25-1 - Update kexec-tools to 2.0.25 - remind the users to run zipl after calling grubby on s390x diff --git a/sources b/sources index 15c98ee..20bacfe 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 SHA512 (kexec-tools-2.0.25.tar.xz) = 6fd3fe11d428c5bb2ce318744146e03ddf752cc77632064bdd7418ef3ad355ad2e2db212d68a5bc73554d78f786901beb42d72bd62e2a4dae34fb224b667ec6b -SHA512 (makedumpfile-1.7.1.tar.gz) = 93e36487b71f567d3685b151459806cf36017e52bf3ee68dd448382b279a422d1a8abef72e291ccb8206f2149ccd08ba484ec0027d1caab3fa1edbc3d28c3632 +SHA512 (makedumpfile-1.7.2.tar.gz) = 324e303dd5f507703f66e2bd5dc9d24f9f50ba797be70c05702008ba77078f61ffcc884796ddf9ab737de1d124c3a9d881ab5ce4f3f459690ec00055af25ea9e From 0a5b71d123ee41b244732fb04d224d36e9ccff84 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 8 Oct 2022 15:41:39 +0800 Subject: [PATCH 275/454] Add lvm2 thin provision dump target checker We need to check if a directory or a device is lvm2 thinp target. First, we use get_block_dump_target() to convert dump path into block device, then we check if the device is lvm2 thinp target by cmd lvs. is_lvm2_thinp_device is now located in kdump-lib-initramfs.sh, for it will be used in 2nd kernel. is_lvm2_thinp_dump_target is located in kdump-lib.sh, for it is only used in 1st kernel, and it has dependencies which exist in kdump-lib.sh. Signed-off-by: Tao Liu Reviewed-by: Philipp Rudo --- kdump-lib-initramfs.sh | 9 +++++++++ kdump-lib.sh | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 52dfcb4..38d71df 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -153,3 +153,12 @@ is_fs_dump_target() { [ -n "$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|virtiofs")" ] } + +is_lvm2_thinp_device() +{ + _device_path=$1 + _lvm2_thin_device=$(lvm lvs -S 'lv_layout=sparse && lv_layout=thin' \ + --nosuffix --noheadings -o vg_name,lv_name "$_device_path" 2> /dev/null) + + [ -n "$_lvm2_thin_device" ] +} diff --git a/kdump-lib.sh b/kdump-lib.sh index b50b4f4..400b05c 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -119,6 +119,12 @@ is_dump_to_rootfs() [[ $(kdump_get_conf_val 'failure_action\|default') == dump_to_rootfs ]] } +is_lvm2_thinp_dump_target() +{ + _target=$(get_block_dump_target) + [ -n "$_target" ] && is_lvm2_thinp_device "$_target" +} + get_failure_action_target() { local _target From 10ca970940f0d8f4edc29737eba1968526182f1e Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 8 Oct 2022 15:41:40 +0800 Subject: [PATCH 276/454] lvm.conf should be check modified if lvm2 thinp enabled lvm2 relies on /etc/lvm/lvm.conf to determine its behaviour. The important configs such as thin_pool_autoextend_threshold and thin_pool_autoextend_percent will be used during kdump in 2nd kernel. So if the file is modified, the initramfs should be rebuild to include the latest. Signed-off-by: Tao Liu Reviewed-by: Philipp Rudo --- kdump-lib-initramfs.sh | 1 + kdumpctl | 1 + 2 files changed, 2 insertions(+) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 38d71df..a893532 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -8,6 +8,7 @@ DEFAULT_SSHKEY="/root/.ssh/kdump_id_rsa" KDUMP_CONFIG_FILE="/etc/kdump.conf" FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" +LVM_CONF="/etc/lvm/lvm.conf" # Read kdump config in well formated style kdump_read_conf() diff --git a/kdumpctl b/kdumpctl index d4d196f..32a5458 100755 --- a/kdumpctl +++ b/kdumpctl @@ -390,6 +390,7 @@ check_files_modified() # HOOKS is mandatory and need to check the modification time files="$files $HOOKS" + is_lvm2_thinp_dump_target && files="$files $LVM_CONF" check_exist "$files" && check_executable "$EXTRA_BINS" || return 2 for file in $files; do From f11721077a5b1ade96d6326c1620d3da0e5eea18 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 8 Oct 2022 15:41:41 +0800 Subject: [PATCH 277/454] Add dependency of dracut lvmthinpool-monitor module The 80lvmthinpool-monitor module is needed for monitor and autoextend the size of thin pool in 2nd kernel. The module was integrated in dracut version 057. If lvmthinpool-monitor module is not found, we will print a warning. Because we don't want to block the kdump process when the thin pool capacity is enough and no monitor-and-autoextend actually needed. Signed-off-by: Tao Liu Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index a790a93..38d2a85 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -40,6 +40,14 @@ depends() { _dep="$_dep ssh-client" fi + if is_lvm2_thinp_dump_target; then + if dracut --list-modules | grep -q lvmthinpool-monitor; then + add_opt_module lvmthinpool-monitor + else + dwarning "Required lvmthinpool-monitor modules is missing! Please upgrade dracut >= 057." + fi + fi + if [[ "$(uname -m)" == "s390x" ]]; then _dep="$_dep znet" fi From 68978f924159b5fc10899941b062e3cc034c8124 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 8 Oct 2022 15:41:42 +0800 Subject: [PATCH 278/454] selftest: Only iterate the .sh files for test execution Previously, all files within $TESTCASEDIR/$test_case are regarded as shell script files for testing. However there might be config files under the directory. So let's only iterate the .sh files. Signed-off-by: Tao Liu Reviewed-by: Philipp Rudo --- tests/scripts/run-test.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/scripts/run-test.sh b/tests/scripts/run-test.sh index 1501db4..0b589f7 100755 --- a/tests/scripts/run-test.sh +++ b/tests/scripts/run-test.sh @@ -85,8 +85,7 @@ for test_case in $testcases; do results[$test_case]="" testdir=$TESTCASEDIR/$test_case - script_num=$(ls -1 $testdir | wc -l) - scripts=$(ls -r -1 $testdir | tr '\n' ' ') + scripts=$(ls -r -1 $testdir | egrep "\.sh$" | tr '\n' ' ') test_outputs="" read main_script aux_script <<< "$scripts" From 6d2c22bb81ee618299df36171d8f85677d4d87d5 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Sat, 8 Oct 2022 15:41:43 +0800 Subject: [PATCH 279/454] selftest: Add lvm2 thin provision for kdump test Signed-off-by: Tao Liu Reviewed-by: Philipp Rudo --- .../lvm2-thinp-kdump/0-local-lvm2-thinp.sh | 59 +++++++++++++++++++ .../testcases/lvm2-thinp-kdump/lvm.conf | 5 ++ 2 files changed, 64 insertions(+) create mode 100755 tests/scripts/testcases/lvm2-thinp-kdump/0-local-lvm2-thinp.sh create mode 100644 tests/scripts/testcases/lvm2-thinp-kdump/lvm.conf diff --git a/tests/scripts/testcases/lvm2-thinp-kdump/0-local-lvm2-thinp.sh b/tests/scripts/testcases/lvm2-thinp-kdump/0-local-lvm2-thinp.sh new file mode 100755 index 0000000..5470aa0 --- /dev/null +++ b/tests/scripts/testcases/lvm2-thinp-kdump/0-local-lvm2-thinp.sh @@ -0,0 +1,59 @@ +on_build() { + TEST_DIR_PREFIX=/tmp/lvm_test.XXXXXX + # clear TEST_DIRs if any + rm -rf ${TEST_DIR_PREFIX%.*}.* + TEST_IMG="$(mktemp -d $TEST_DIR_PREFIX)/test.img" + + img_inst_pkg "lvm2" + img_inst $TESTDIR/scripts/testcases/lvm2-thinp-kdump/lvm.conf /etc/lvm/ + dd if=/dev/zero of=$TEST_IMG bs=300M count=1 + # The test.img will be /dev/sdb + img_add_qemu_cmd "-hdb $TEST_IMG" +} + +on_test() { + VG=vg00 + LV_THINPOOL=thinpool + LV_VOLUME=thinlv + VMCORE_PATH=var/crash + + local boot_count=$(get_test_boot_count) + + if [ $boot_count -eq 1 ]; then + + vgcreate $VG /dev/sdb + # Create a small thinpool which is definitely not enough for + # vmcore, then create a thin volume which is definitely enough + # for vmcore, so we can make sure thinpool should be autoextend + # during runtime. + lvcreate -L 10M -T $VG/$LV_THINPOOL + lvcreate -V 300M -T $VG/$LV_THINPOOL -n $LV_VOLUME + mkfs.ext4 /dev/$VG/$LV_VOLUME + mount /dev/$VG/$LV_VOLUME /mnt + mkdir -p /mnt/$VMCORE_PATH + + cat << EOF > /etc/kdump.conf +ext4 /dev/$VG/$LV_VOLUME +path /$VMCORE_PATH +core_collector makedumpfile -l --message-level 7 -d 31 +EOF + kdumpctl start || test_failed "Failed to start kdump" + + sync + + echo 1 > /proc/sys/kernel/sysrq + echo c > /proc/sysrq-trigger + + elif [ $boot_count -eq 2 ]; then + mount /dev/$VG/$LV_VOLUME /mnt + if has_valid_vmcore_dir /mnt/$VMCORE_PATH; then + test_passed + else + test_failed "Vmcore missing" + fi + + shutdown -h 0 + else + test_failed "Unexpected reboot" + fi +} diff --git a/tests/scripts/testcases/lvm2-thinp-kdump/lvm.conf b/tests/scripts/testcases/lvm2-thinp-kdump/lvm.conf new file mode 100644 index 0000000..4d81fbd --- /dev/null +++ b/tests/scripts/testcases/lvm2-thinp-kdump/lvm.conf @@ -0,0 +1,5 @@ +activation { + thin_pool_autoextend_threshold = 70 + thin_pool_autoextend_percent = 20 + monitoring = 1 +} \ No newline at end of file From 55b0dd03b36556b40e1f0d660b76bc5acb99b982 Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Mon, 31 Oct 2022 15:42:20 +0530 Subject: [PATCH 280/454] fadump: do not use squash to reduce image size With commit fa9201b2 ("fadump: isolate fadump initramfs image within the default one"), initramfs image gets to hold two squash images, one for production kernel boot purpose and the other for capture kernel boot. Having separate images improved reliability for both production kernel and capture kernel boot scenarios, but the size of initramfs image became considerably larger. Instead of having squash images, compressing $initdir without using squash images reduced the size of initramfs image for fadump case by around 30%. So, avoid using squash for fadump case. Signed-off-by: Hari Bathini Reviewed-by: Philipp Rudo --- mkfadumprd | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mkfadumprd b/mkfadumprd index f353f15..1e09ac2 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -38,7 +38,9 @@ FADUMP_INITRD="$MKFADUMPRD_TMPDIR/fadump.img" # this file tells the initrd is fadump enabled touch "$MKFADUMPRD_TMPDIR/fadump.initramfs" ddebug "rebuild fadump initrd: $FADUMP_INITRD $DEFAULT_INITRD $KDUMP_KERNELVER" -if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs; then +# Don't use squash for capture image or default image as it negatively impacts +# compression ratio and increases the size of the initramfs image. +if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs --omit squash; then perror_exit "mkfadumprd: failed to build image with dump capture support" fi @@ -58,10 +60,6 @@ _dracut_isolate_args=( /usr/lib/dracut/fadump-kernel-modules.txt ) -if is_squash_available; then - _dracut_isolate_args+=(--add squash) -fi - # Same as setting zstd in mkdumprd if ! have_compression_in_dracut_args; then if is_squash_available && dracut_have_option "--squash-compressor"; then From f33c99e34749e976b610ad939f507cc471b33980 Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Mon, 31 Oct 2022 15:42:21 +0530 Subject: [PATCH 281/454] fadump: preserve file modification time to help with hardlinking With commit fa9201b2 ("fadump: isolate fadump initramfs image within the default one"), initramfs image gets to hold two images, one for production kernel boot purpose and the other for capture kernel boot. Most files are common among the two images. Retain file modification time to replace duplicate files with hardlinks and save space. Also, avoid unnecessarily compressing fadump image that is decompressed immediately anyway. Signed-off-by: Hari Bathini Reviewed-by: Philipp Rudo --- mkfadumprd | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mkfadumprd b/mkfadumprd index 1e09ac2..36ad645 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -40,14 +40,16 @@ touch "$MKFADUMPRD_TMPDIR/fadump.initramfs" ddebug "rebuild fadump initrd: $FADUMP_INITRD $DEFAULT_INITRD $KDUMP_KERNELVER" # Don't use squash for capture image or default image as it negatively impacts # compression ratio and increases the size of the initramfs image. -if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs --omit squash; then +# Don't compress the capture image as uncompressed image is needed immediately. +# Also, early microcode would not be needed here. +if ! $MKDUMPRD "$FADUMP_INITRD" -i "$MKFADUMPRD_TMPDIR/fadump.initramfs" /etc/fadump.initramfs --omit squash --no-compress --no-early-microcode; then perror_exit "mkfadumprd: failed to build image with dump capture support" fi -### Unpack the initramfs having dump capture capability +### Unpack the initramfs having dump capture capability retaining previous file modification time. +# This helps in saving space by hardlinking identical files. mkdir -p "$MKFADUMPRD_TMPDIR/fadumproot" -if ! (pushd "$MKFADUMPRD_TMPDIR/fadumproot" > /dev/null && lsinitrd --unpack "$FADUMP_INITRD" && - popd > /dev/null); then +if ! cpio -id --preserve-modification-time --quiet -D "$MKFADUMPRD_TMPDIR/fadumproot" < "$FADUMP_INITRD"; then derror "mkfadumprd: failed to unpack '$MKFADUMPRD_TMPDIR'" exit 1 fi From cea74a7b3e2e8c8eff65c68354f0b16e8558a888 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 25 Oct 2022 18:02:04 +0800 Subject: [PATCH 282/454] tests: use .nmconnection to set up test network F36 has dropped support on ifcfg and as a result current network tests fails. Use .nmconnection to set up test network instead. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- tests/scripts/testcases/nfs-kdump/0-server.sh | 13 +++++++------ tests/scripts/testcases/ssh-kdump/0-server.sh | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/scripts/testcases/nfs-kdump/0-server.sh b/tests/scripts/testcases/nfs-kdump/0-server.sh index cf54e70..5436d3d 100755 --- a/tests/scripts/testcases/nfs-kdump/0-server.sh +++ b/tests/scripts/testcases/nfs-kdump/0-server.sh @@ -16,12 +16,13 @@ on_build() { img_run_cmd "echo dhcp-range=192.168.77.50,192.168.77.100,255.255.255.0,12h >> /etc/dnsmasq.conf" img_run_cmd "systemctl enable dnsmasq" - img_run_cmd 'echo DEVICE="eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo BOOTPROTO="none" >> /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo ONBOOT="yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo PREFIX="24" >> /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo IPADDR="192.168.77.1" >> /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo TYPE="Ethernet" >> /etc/sysconfig/network-scripts/ifcfg-eth0' + img_run_cmd 'echo [connection] > /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo type=ethernet >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo interface-name=eth0 >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo [ipv4] >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo address1=192.168.77.1/24 >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo method=manual >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'chmod 600 /etc/NetworkManager/system-connections/eth0.nmconnection' img_add_qemu_cmd "-nic socket,listen=:8010,mac=52:54:00:12:34:56" } diff --git a/tests/scripts/testcases/ssh-kdump/0-server.sh b/tests/scripts/testcases/ssh-kdump/0-server.sh index 6dfcc91..b4b84c9 100755 --- a/tests/scripts/testcases/ssh-kdump/0-server.sh +++ b/tests/scripts/testcases/ssh-kdump/0-server.sh @@ -17,12 +17,13 @@ on_build() { img_run_cmd "echo dhcp-range=192.168.77.50,192.168.77.100,255.255.255.0,12h >> /etc/dnsmasq.conf" img_run_cmd "systemctl enable dnsmasq" - img_run_cmd 'echo DEVICE="eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo BOOTPROTO="none >> /etc/sysconfig/network-scripts/ifcfg-eth0"' - img_run_cmd 'echo ONBOOT="yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo PREFIX="24" >> /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo IPADDR="192.168.77.1" >> /etc/sysconfig/network-scripts/ifcfg-eth0' - img_run_cmd 'echo TYPE="Ethernet" >> /etc/sysconfig/network-scripts/ifcfg-eth0' + img_run_cmd 'echo [connection] > /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo type=ethernet >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo interface-name=eth0 >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo [ipv4] >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo address1=192.168.77.1/24 >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'echo method=manual >> /etc/NetworkManager/system-connections/eth0.nmconnection' + img_run_cmd 'chmod 600 /etc/NetworkManager/system-connections/eth0.nmconnection' } # Executed when VM boots From 3ae8cf8876edd6ca668890f55d4c006e28a41f90 Mon Sep 17 00:00:00 2001 From: Tao Liu Date: Thu, 10 Nov 2022 10:25:58 +0800 Subject: [PATCH 283/454] Don't check fs modified when dump target is lvm2 thinp When the dump target is lvm2 thinp, if we didn't mount the dump target first, get_fs_type_from_target will get empty output: Before mount: $ get_fs_type_from_target /dev/vg00/thinlv After mount: $ mount /dev/vg00/thinlv /mnt $ get_fs_type_from_target /dev/vg00/thinlv ext4 As a result, kdumpctl start will fail with: $ kdumpctl start kdump: Dump target is invalid kdump: Starting kdump: [FAILED] This patch fix the issue by bypassing check_fs_modified when the dump target is lvm2 thinp. Signed-off-by: Tao Liu Reviewed-by: Coiby Xu --- kdumpctl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 32a5458..7caaae5 100755 --- a/kdumpctl +++ b/kdumpctl @@ -479,8 +479,9 @@ check_fs_modified() fi # No need to check in case of raw target. - # Currently we do not check also if ssh/nfs/virtiofs target is specified - if is_ssh_dump_target || is_nfs_dump_target || is_raw_dump_target || is_virtiofs_dump_target; then + # Currently we do not check also if ssh/nfs/virtiofs/thinp target is specified + if is_ssh_dump_target || is_nfs_dump_target || is_raw_dump_target || + is_virtiofs_dump_target || is_lvm2_thinp_dump_target; then return 0 fi From a3da46d6c418d694eba6dc44fe91d841751f164d Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 18 Nov 2022 17:11:25 +0800 Subject: [PATCH 284/454] Skip reset_crashkernel_after_update during package install Currently, kexec-tools tries to reset crashkernel when using anaconda to install the system. But grubby isn't ready and complains that, 10:34:17,014 INF packaging: Configuring (running scriptlet for): kexec-tools-2.0.23-9.el9.x86_64 1646034766 53ff7158f8808774f4e3c3c87e504aa7a6d677b537754dac86c87925c8f0a397 10:34:17,205 INF dnf.rpm: grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory kexec-tools is supposed to update the kernel crashkernel parameter after package upgrade. Unfortunately, the posttrans RPM scriptlet doesn't distinguish between package install and upgrade. This patch skips reset_crashkernel_after_update as similar to e218128e ("Only try to reset crashkernel for osbuild during package install"). Reported-by: Jan Stodola Signed-off-by: Coiby Xu --- kdumpctl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kdumpctl b/kdumpctl index 7caaae5..b82d869 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1657,6 +1657,10 @@ reset_crashkernel_after_update() local _kernel _crashkernel _dump_mode _fadump_val _old_default_crashkernel _new_default_crashkernel declare -A _crashkernel_vals + if _is_package_install; then + return + fi + _crashkernel_vals[old_kdump]=$(cat /tmp/old_default_crashkernel 2> /dev/null) _crashkernel_vals[old_fadump]=$(cat /tmp/old_default_crashkernel_fadump 2> /dev/null) _crashkernel_vals[new_kdump]=$(get_default_crashkernel kdump) From b7e58619d175ccefcd1cfc2e9801ffb4448d0257 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 13 Sep 2021 22:13:44 +0800 Subject: [PATCH 285/454] Fix error for vlan over team network interface 6f9235887f7817085aabfcc67bf4a6d68e474264 ("module-setup.sh: enable vlan on team interface") skips establishing teaming network by mistake. Although it could use one of slave netifs to establish connection to transfer vmcore to remote fs, it breaks the implicit assumption of creating an identical network topology to the 1st kernel. Fixes: 6f92358 ("module-setup.sh: enable vlan on team interface") Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 38d2a85..668768e 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -445,6 +445,9 @@ kdump_setup_vlan() { elif kdump_is_bond "$_phydev"; then (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_apath_by_ifname "$_phydev")") || exit 1 echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" + elif kdump_is_team "$_phydev"; then + (kdump_setup_team "$_phydev") || exit 1 + echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" else _kdumpdev="$(kdump_setup_ifname "$_phydev")" echo " vlan=$(kdump_setup_ifname "$_netdev"):$_kdumpdev ifname=$_kdumpdev:$_netmac" > "${initdir}/etc/cmdline.d/43vlan.conf" From d25b1ee31c0c7eee43362c96d5e76f6fb0e90a25 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 9 Sep 2021 11:35:52 +0800 Subject: [PATCH 286/454] Add functions to copy NetworkManage connection profiles to the initramfs Each network interface is manged by a NM connection. Given a list of network interface names, copy the NetworkManager (NM) connection profiles i.e. .nmconnection files to the kdump initramfs. Before copying a connection file, clone it to automatically convert a legacy ifcfg-*[1] file to a .nmconnection file and for the convenience of editing the connection profile. [1] https://fedoraproject.org/wiki/Changes/NetworkManager_keyfile_instead_of_ifcfg_rh Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 77 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 668768e..4a213e0 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1,10 +1,21 @@ #!/bin/bash +_DRACUT_KDUMP_NM_TMP_DIR="/tmp/$$-DRACUT_KDUMP_NM" + +cleanup() { + rm -rf "$_DRACUT_KDUMP_NM_TMP_DIR" +} + +# shellcheck disable=SC2154 # known issue of shellcheck https://github.com/koalaman/shellcheck/issues/1299 +trap 'ret=$?; cleanup; exit $ret;' EXIT + kdump_module_init() { if ! [[ -d "${initdir}/tmp" ]]; then mkdir -p "${initdir}/tmp" fi + mkdir -p "$_DRACUT_KDUMP_NM_TMP_DIR" + . /lib/kdump/kdump-lib.sh } @@ -354,6 +365,71 @@ kdump_setup_ifname() { echo "$_ifname" } +_clone_nmconnection() { + local _clone_output _name _unique_id + + _unique_id=$1 + _name=$(nmcli --get-values connection.id connection show "$_unique_id") + if _clone_output=$(nmcli connection clone --temporary uuid "$_unique_id" "$_name"); then + sed -E -n "s/.* \(.*\) cloned as.*\((.*)\)\.$/\1/p" <<< "$_clone_output" + return 0 + fi + + return 1 +} + +# Clone and modify NM connection profiles +# +# This function makes use of "nmcli clone" to automatically convert ifcfg-* +# files to Networkmanager .nmconnection connection profiles and also modify the +# properties of .nmconnection if necessary. +clone_and_modify_nmconnection() { + local _dev _cloned_nmconnection_file_path _tmp_nmconnection_file_path _old_uuid _uuid + + _dev=$1 + _nmconnection_file_path=$2 + + _old_uuid=$(nmcli --get-values connection.uuid connection show filename "$_nmconnection_file_path") + + if ! _uuid=$(_clone_nmconnection "$_old_uuid"); then + derror "Failed to clone $_old_uuid" + exit 1 + fi + + _cloned_nmconnection_file_path=$(nmcli --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p") + _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename "$_nmconnection_file_path") + cp "$_cloned_nmconnection_file_path" "$_tmp_nmconnection_file_path" + # change uuid back to old value in case it's refered by other connection + # profile e.g. connection.master could be interface name of the master + # device or UUID of the master connection. + sed -i -E "s/(^uuid=).*$/\1${_old_uuid}/g" "$_tmp_nmconnection_file_path" + nmcli connection del "$_uuid" &> >(ddebug) + echo -n "$_tmp_nmconnection_file_path" +} + +_install_nmconnection() { + local _src _nmconnection_name _dst + + _src=$1 + _nmconnection_name=$(basename "$_src") + _dst="/etc/NetworkManager/system-connections/$_nmconnection_name" + inst "$_src" "$_dst" +} + +kdump_install_nmconnections() { + local _netif _nm_conn_path _cloned_nm_path + + while IFS=: read -r _netif _nm_conn_path; do + [[ -v "unique_netifs[$_netif]" ]] || continue + if _cloned_nm_path=$(clone_and_modify_nmconnection "$_netif" "$_nm_conn_path"); then + _install_nmconnection "$_cloned_nm_path" + else + derror "Failed to install the .nmconnection for $_netif" + exit 1 + fi + done <<< "$(nmcli -t -f device,filename connection show --active)" +} + kdump_setup_bridge() { local _netdev=$1 local _brif _dev _mac _kdumpdev @@ -1030,6 +1106,7 @@ remove_cpu_online_rule() { } install() { + declare -A unique_netifs local arch kdump_module_init From 9dfcacf72d2cd135bf8b72c4bbc97f15efa21250 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 8 Sep 2022 17:06:19 +0800 Subject: [PATCH 287/454] Determine whether IPv4 or IPv6 is needed According to `man nm-online`, "By default, connections have the ipv4.may-fail and ipv6.may-fail properties set to yes; this means that NetworkManager waits for one of the two address families to complete configuration before considering the connection activated. If you need a specific address family configured before network-online.target is reached, set the corresponding may-fail property to no." If a NIC has an IPv4 or IPv6 address, set the corresponding may-fail property to no. Otherwise, dumping vmcore over IPv6 could fail because only IPv4 network is ready or vice versa. Also disable IPv6 if only IPv4 is used and vice versa. Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 4a213e0..e5ca6f7 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -365,6 +365,24 @@ kdump_setup_ifname() { echo "$_ifname" } +use_ipv4_or_ipv6() { + local _netif=$1 _uuid=$2 + + if [[ -v "ipv4_usage[$_netif]" ]]; then + nmcli connection modify --temporary "$_uuid" ipv4.may-fail no &> >(ddebug) + fi + + if [[ -v "ipv6_usage[$_netif]" ]]; then + nmcli connection modify --temporary "$_uuid" ipv6.may-fail no &> >(ddebug) + fi + + if [[ -v "ipv4_usage[$_netif]" ]] && [[ ! -v "ipv6_usage[$_netif]" ]]; then + nmcli connection modify --temporary "$_uuid" ipv6.method disabled &> >(ddebug) + elif [[ ! -v "ipv4_usage[$_netif]" ]] && [[ -v "ipv6_usage[$_netif]" ]]; then + nmcli connection modify --temporary "$_uuid" ipv4.method disabled &> >(ddebug) + fi +} + _clone_nmconnection() { local _clone_output _name _unique_id @@ -396,6 +414,8 @@ clone_and_modify_nmconnection() { exit 1 fi + use_ipv4_or_ipv6 "$_dev" "$_uuid" + _cloned_nmconnection_file_path=$(nmcli --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p") _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename "$_nmconnection_file_path") cp "$_cloned_nmconnection_file_path" "$_tmp_nmconnection_file_path" @@ -1106,7 +1126,7 @@ remove_cpu_online_rule() { } install() { - declare -A unique_netifs + declare -A unique_netifs ipv4_usage ipv6_usage local arch kdump_module_init From 6b586a903632831b05f591048fdb7de4af273088 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 22 Sep 2022 22:08:43 +0800 Subject: [PATCH 288/454] Apply the timeout configuration of nm-initrd-generator nm-wait-online-initrd.service installed by dracut's 35-networkmanager module calls nm-online with "-s" which means it returns immediately when NetworkManager logs "startup complete" after certain timeouts are reached. "startup complete" doesn't necessarily network connectivity has been established. nm-initrd-generator has a set of timeouts that in most of cases when applied, "startup-complete" means network connectivity has been established. So apply it when setting up kdump network. Suggested-by: Thomas Haller Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index e5ca6f7..aeff5fc 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -365,6 +365,22 @@ kdump_setup_ifname() { echo "$_ifname" } +apply_nm_initrd_generator_timeouts() { + local _timeout_conf + + _timeout_conf=$_DRACUT_KDUMP_NM_TMP_DIR/timeout_conf + cat << EOF > "$_timeout_conf" +[device-95-kdump] +carrier-wait-timeout=30000 + +[connection-95-kdump] +ipv4.dhcp-timeout=90 +ipv6.dhcp-timeout=90 +EOF + + inst "$_timeout_conf" "/etc/NetworkManager/conf.d/95-kdump-timeouts.conf" +} + use_ipv4_or_ipv6() { local _netif=$1 _uuid=$2 @@ -416,6 +432,7 @@ clone_and_modify_nmconnection() { use_ipv4_or_ipv6 "$_dev" "$_uuid" + nmcli connection modify --temporary uuid "$_uuid" connection.wait-device-timeout 60000 &> >(ddebug) _cloned_nmconnection_file_path=$(nmcli --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p") _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename "$_nmconnection_file_path") cp "$_cloned_nmconnection_file_path" "$_tmp_nmconnection_file_path" From 62355ebe5abed6fdd3331bbb2f07c64d3434d159 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 23 Sep 2022 22:16:49 +0800 Subject: [PATCH 289/454] Stop dracut 35network-manager from running nm-initrd-generator kexec-tools depends on dracut's 35network-manager module which will call nm-initrd-generator. We don't want nm-initrd-generator to generate connection profiles since we will copy them from 1st kernel to kdump kernel initramfs. NetworkManager >= 1.35.2 won't generate connection profiles if there's a connection dir with rd.neednet. For Fedora/RHEL, this connection dir is /etc/NetworkManager/system-connections. For the details, please refer to the NetworkManager commit 79885656d3 ("initrd: don't add a connection if there's a connection dir with rd.neednet") [1]. Before the release of NetworkManager >= 1.35.2, we need to mask /usr/libexec/nm-initrd-generator. [1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1010 Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index aeff5fc..ecfabc7 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -465,6 +465,11 @@ kdump_install_nmconnections() { exit 1 fi done <<< "$(nmcli -t -f device,filename connection show --active)" + + # Stop dracut 35network-manger to calling nm-initrd-generator. + # Note this line of code can be removed after NetworkManager >= 1.35.2 + # gets released. + echo > "${initdir}/usr/libexec/nm-initrd-generator" } kdump_setup_bridge() { From 63c3805c486adf700bafb5ad78cc9b0f55fcb345 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 17 Sep 2021 13:02:07 +0800 Subject: [PATCH 290/454] Set up kdump network by directly copying NM connection profile to initrd This patch setup kdump network by directly copying NM connection profile(s) for different network setup including bond, bridge, vlan, and team. For vlan network, rename phydev to parent_netif to improve code readability. With the new approach, the related code to build up dracut cmdline parameter such rd.route, ip and etc can be cleaned up. And there is no need to setup dns when copying .nmconnection directly to initrd either. Note the bootdev dracut command line parameter is only used by dracut's 35network-legacy and network-manager doesn't use it, remove related code as well. Note 1. kdump_setup_vlan/bond/... are no longer called in subshells in order to modify global variables like unique_netifs 2. The original kdump_install_net is renamed to better reflect its current function Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 287 ++++++++--------------------------------- 1 file changed, 57 insertions(+), 230 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index ecfabc7..67468cd 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -2,6 +2,14 @@ _DRACUT_KDUMP_NM_TMP_DIR="/tmp/$$-DRACUT_KDUMP_NM" +_save_kdump_netifs() { + unique_netifs[$1]=1 +} + +_get_kdump_netifs() { + echo -n "${!unique_netifs[@]}" +} + cleanup() { rm -rf "$_DRACUT_KDUMP_NM_TMP_DIR" } @@ -103,39 +111,6 @@ source_ifcfg_file() { fi } -kdump_setup_dns() { - local _netdev="$1" - local _conpath="$2" - local _nameserver _dns _tmp array - local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf - - _tmp=$(get_nmcli_field_by_conpath "IP4.DNS" "$_conpath") - # shellcheck disable=SC2206 - array=(${_tmp//|/ }) - if [[ ${array[*]} ]]; then - for _dns in "${array[@]}"; do - echo "nameserver=$_dns" >> "$_dnsfile" - done - else - dwarning "Failed to get DNS info via nmcli output. Now try sourcing ifcfg script" - source_ifcfg_file "$_netdev" - [[ -n $DNS1 ]] && echo "nameserver=$DNS1" > "$_dnsfile" - [[ -n $DNS2 ]] && echo "nameserver=$DNS2" >> "$_dnsfile" - fi - - while read -r content; do - _nameserver=$(echo "$content" | grep ^nameserver) - [[ -z $_nameserver ]] && continue - - _dns=$(echo "$_nameserver" | awk '{print $2}') - [[ -z $_dns ]] && continue - - if [[ ! -f $_dnsfile ]] || ! grep -q "$_dns" "$_dnsfile"; then - echo "nameserver=$_dns" >> "$_dnsfile" - fi - done < "/etc/resolv.conf" -} - # $1: repeat times # $2: string to be repeated # $3: separator @@ -246,89 +221,6 @@ cal_netmask_by_prefix() { fi } -#$1: netdev name -#$2: srcaddr -#if it use static ip echo it, or echo null -kdump_static_ip() { - local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag - local _netmask _gateway _ipaddr _target _nexthop _prefix - - _ipaddr=$(ip addr show dev "$_netdev" permanent | awk "/ $_srcaddr\/.* /{print \$2}") - - if is_ipv6_address "$_srcaddr"; then - _ipv6_flag="-6" - fi - - if [[ -n $_ipaddr ]]; then - _gateway=$(ip $_ipv6_flag route list dev "$_netdev" \ - | awk '/^default /{print $3}' | head -n 1) - - if [[ "x" != "x"$_ipv6_flag ]]; then - # _ipaddr="2002::56ff:feb6:56d5/64", _netmask is the number after "/" - _netmask=${_ipaddr#*\/} - _srcaddr="[$_srcaddr]" - _gateway="[$_gateway]" - else - _prefix=$(cut -d'/' -f2 <<< "$_ipaddr") - if ! _netmask=$(cal_netmask_by_prefix "$_prefix" "$_ipv6_flag"); then - derror "Failed to calculate netmask for $_ipaddr" - exit 1 - fi - fi - echo -n "${_srcaddr}::${_gateway}:${_netmask}::" - fi - - /sbin/ip $_ipv6_flag route show | grep -v default \ - | grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" \ - | while read -r _route; do - _target=$(echo "$_route" | awk '{print $1}') - _nexthop=$(echo "$_route" | awk '{print $3}') - if [[ "x" != "x"$_ipv6_flag ]]; then - _target="[$_target]" - _nexthop="[$_nexthop]" - fi - echo "rd.route=$_target:$_nexthop:$kdumpnic" - done >> "${initdir}/etc/cmdline.d/45route-static.conf" - - kdump_handle_mulitpath_route "$_netdev" "$_srcaddr" "$kdumpnic" -} - -kdump_handle_mulitpath_route() { - local _netdev="$1" _srcaddr="$2" kdumpnic="$3" _ipv6_flag - local _target _nexthop _route _weight _max_weight _rule - - if is_ipv6_address "$_srcaddr"; then - _ipv6_flag="-6" - fi - - while IFS="" read -r _route; do - if [[ $_route =~ [[:space:]]+nexthop ]]; then - _route=${_route##[[:space:]]} - # Parse multipath route, using previous _target - [[ $_target == 'default' ]] && continue - [[ $_route =~ .*via.*\ $_netdev ]] || continue - - _weight=$(echo "$_route" | cut -d ' ' -f7) - if [[ $_weight -gt $_max_weight ]]; then - _nexthop=$(echo "$_route" | cut -d ' ' -f3) - _max_weight=$_weight - if [[ "x" != "x"$_ipv6_flag ]]; then - _rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic" - else - _rule="rd.route=$_target:$_nexthop:$kdumpnic" - fi - fi - else - [[ -n $_rule ]] && echo "$_rule" - _target=$(echo "$_route" | cut -d ' ' -f1) - _rule="" _max_weight=0 _weight=0 - fi - done >> "${initdir}/etc/cmdline.d/45route-static.conf" \ - <<< "$(/sbin/ip $_ipv6_flag route show)" - - [[ -n $_rule ]] && echo "$_rule" >> "${initdir}/etc/cmdline.d/45route-static.conf" -} - kdump_get_mac_addr() { cat "/sys/class/net/$1/address" } @@ -474,102 +366,55 @@ kdump_install_nmconnections() { kdump_setup_bridge() { local _netdev=$1 - local _brif _dev _mac _kdumpdev + local _dev for _dev in "/sys/class/net/$_netdev/brif/"*; do [[ -e $_dev ]] || continue _dev=${_dev##*/} - _kdumpdev=$_dev if kdump_is_bond "$_dev"; then - (kdump_setup_bond "$_dev" "$(get_nmcli_connection_apath_by_ifname "$_dev")") || exit 1 + kdump_setup_bond "$_dev" || return 1 elif kdump_is_team "$_dev"; then kdump_setup_team "$_dev" elif kdump_is_vlan "$_dev"; then kdump_setup_vlan "$_dev" - else - _mac=$(kdump_get_mac_addr "$_dev") - _kdumpdev=$(kdump_setup_ifname "$_dev") - echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/41bridge.conf" fi - _brif+="$_kdumpdev," + _save_kdump_netifs "$_dev" done - echo " bridge=$_netdev:${_brif%,}" >> "${initdir}/etc/cmdline.d/41bridge.conf" } -# drauct takes bond=[::[:]] syntax to parse -# bond. For example: -# bond=bond0:eth0,eth1:mode=balance-rr kdump_setup_bond() { local _netdev="$1" - local _conpath="$2" - local _dev _mac _slaves _kdumpdev _bondoptions - for _dev in $(cat "/sys/class/net/$_netdev/bonding/slaves"); do - _mac=$(kdump_get_perm_addr "$_dev") - _kdumpdev=$(kdump_setup_ifname "$_dev") - echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/42bond.conf" - _slaves+="$_kdumpdev," + local _dev + + for _dev in $(< "/sys/class/net/$_netdev/bonding/slaves"); do + _save_kdump_netifs "$_dev" done - echo -n " bond=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/42bond.conf" - - _bondoptions=$(get_nmcli_field_by_conpath "bond.options" "$_conpath") - - if [[ -z $_bondoptions ]]; then - dwarning "Failed to get bond configuration via nmlci output. Now try sourcing ifcfg script." - source_ifcfg_file "$_netdev" - _bondoptions="$(echo "$BONDING_OPTS" | xargs echo | tr " " ",")" - fi - - if [[ -z $_bondoptions ]]; then - derror "Get empty bond options" - exit 1 - fi - - echo ":$_bondoptions" >> "${initdir}/etc/cmdline.d/42bond.conf" } kdump_setup_team() { local _netdev=$1 - local _dev _mac _slaves _kdumpdev + local _dev for _dev in $(teamnl "$_netdev" ports | awk -F':' '{print $2}'); do - _mac=$(kdump_get_perm_addr "$_dev") - _kdumpdev=$(kdump_setup_ifname "$_dev") - echo -n " ifname=$_kdumpdev:$_mac" >> "${initdir}/etc/cmdline.d/44team.conf" - _slaves+="$_kdumpdev," + _save_kdump_netifs "$_dev" done - echo " team=$_netdev:${_slaves%,}" >> "${initdir}/etc/cmdline.d/44team.conf" - #Buggy version teamdctl outputs to stderr! - #Try to use the latest version of teamd. - if ! teamdctl "$_netdev" config dump > "${initdir}/tmp/$$-$_netdev.conf"; then - derror "teamdctl failed." - exit 1 - fi - inst_dir /etc/teamd - inst_simple "${initdir}/tmp/$$-$_netdev.conf" "/etc/teamd/$_netdev.conf" - rm -f "${initdir}/tmp/$$-$_netdev.conf" } kdump_setup_vlan() { local _netdev=$1 - local _phydev - local _netmac - local _kdumpdev + local _parent_netif - _phydev="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" - _netmac="$(kdump_get_mac_addr "$_phydev")" + _parent_netif="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" #Just support vlan over bond and team - if kdump_is_bridge "$_phydev"; then + if kdump_is_bridge "$_parent_netif"; then derror "Vlan over bridge is not supported!" exit 1 - elif kdump_is_bond "$_phydev"; then - (kdump_setup_bond "$_phydev" "$(get_nmcli_connection_apath_by_ifname "$_phydev")") || exit 1 - echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" - elif kdump_is_team "$_phydev"; then - (kdump_setup_team "$_phydev") || exit 1 - echo " vlan=$(kdump_setup_ifname "$_netdev"):$_phydev" > "${initdir}/etc/cmdline.d/43vlan.conf" - else - _kdumpdev="$(kdump_setup_ifname "$_phydev")" - echo " vlan=$(kdump_setup_ifname "$_netdev"):$_kdumpdev ifname=$_kdumpdev:$_netmac" > "${initdir}/etc/cmdline.d/43vlan.conf" + elif kdump_is_bond "$_parent_netif"; then + kdump_setup_bond "$_parent_netif" || return 1 + elif kdump_is_team "$_parent_netif"; then + kdump_setup_team "$_parent_netif" || return 1 fi + + _save_kdump_netifs "$_parent_netif" } # find online znet device @@ -656,20 +501,16 @@ kdump_get_remote_ip() { echo "$_remote" } -# Setup dracut to bring up network interface that enable -# initramfs accessing giving destination +# Collect netifs needed by kdump # $1: destination host -kdump_install_net() { - local _destaddr _srcaddr _route _netdev _conpath kdumpnic - local _static _proto _ip_conf _ip_opts _ifname_opts +kdump_collect_netif_usage() { + local _destaddr _srcaddr _route _netdev kdumpnic local _znet_netdev _znet_conpath _destaddr=$(kdump_get_remote_ip "$1") _route=$(kdump_get_ip_route "$_destaddr") _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") - _conpath=$(get_nmcli_connection_apath_by_ifname "$_netdev") - _netmac=$(kdump_get_mac_addr "$_netdev") kdumpnic=$(kdump_setup_ifname "$_netdev") _znet_netdev=$(find_online_znet_device) @@ -681,58 +522,42 @@ kdump_install_net() { fi fi - _static=$(kdump_static_ip "$_netdev" "$_srcaddr" "$kdumpnic") - if [[ -n $_static ]]; then - _proto=none - elif is_ipv6_address "$_srcaddr"; then - _proto=auto6 - else - _proto=dhcp - fi - - _ip_conf="${initdir}/etc/cmdline.d/40ip.conf" - _ip_opts=" ip=${_static}$kdumpnic:${_proto}" - - # dracut doesn't allow duplicated configuration for same NIC, even they're exactly the same. - # so we have to avoid adding duplicates - # We should also check /proc/cmdline for existing ip=xx arg. - # For example, iscsi boot will specify ip=xxx arg in cmdline. - if [[ ! -f $_ip_conf ]] || ! grep -q "$_ip_opts" "$_ip_conf" \ - && ! grep -q "ip=[^[:space:]]*$_netdev" /proc/cmdline; then - echo "$_ip_opts" >> "$_ip_conf" - fi - if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then - (kdump_setup_bond "$_netdev" "$_conpath") || exit 1 + kdump_setup_bond "$_netdev" || return 1 elif kdump_is_team "$_netdev"; then kdump_setup_team "$_netdev" elif kdump_is_vlan "$_netdev"; then kdump_setup_vlan "$_netdev" - else - _ifname_opts=" ifname=$kdumpnic:$_netmac" - echo "$_ifname_opts" >> "$_ip_conf" fi - - kdump_setup_dns "$_netdev" "$_conpath" + _save_kdump_netifs "$_netdev" if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then # network-manager module needs this parameter echo "rd.neednet" >> "${initdir}/etc/cmdline.d/50neednet.conf" fi - # Save netdev used for kdump as cmdline - # Whoever calling kdump_install_net() is setting up the default gateway, - # ie. bootdev/kdumpnic. So don't override the setting if calling - # kdump_install_net() for another time. For example, after setting eth0 as - # the default gate way for network dump, eth1 in the fence kdump path will - # call kdump_install_net again and we don't want eth1 to be the default - # gateway. - if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]] \ - && [[ ! -f ${initdir}/etc/cmdline.d/70bootdev.conf ]]; then + if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]]; then echo "kdumpnic=$kdumpnic" > "${initdir}/etc/cmdline.d/60kdumpnic.conf" - echo "bootdev=$kdumpnic" > "${initdir}/etc/cmdline.d/70bootdev.conf" + fi + + if is_ipv6_address "$_srcaddr"; then + ipv6_usage[$_netdev]=1 + else + ipv4_usage[$_netdev]=1 + fi +} + +# Setup dracut to bring up network interface that enable +# initramfs accessing giving destination +kdump_install_net() { + local _netifs + + _netifs=$(_get_kdump_netifs) + if [[ -n "$_netifs" ]]; then + kdump_install_nmconnections + apply_nm_initrd_generator_timeouts fi } @@ -771,7 +596,7 @@ default_dump_target_install_conf() { _fstype=$(get_fs_type_from_target "$_target") if is_fs_type_nfs "$_fstype"; then - kdump_install_net "$_target" + kdump_collect_netif_usage "$_target" _fstype="nfs" else _target=$(kdump_get_persistent_dev "$_target") @@ -807,11 +632,11 @@ kdump_install_conf() { sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" ;; ssh | nfs) - kdump_install_net "$_val" + kdump_collect_netif_usage "$_val" ;; dracut_args) if [[ $(get_dracut_args_fstype "$_val") == nfs* ]]; then - kdump_install_net "$(get_dracut_args_target "$_val")" + kdump_collect_netif_usage "$(get_dracut_args_target "$_val")" fi ;; kdump_pre | kdump_post | extra_bins) @@ -933,7 +758,7 @@ kdump_setup_iscsi_device() { [[ -n $username_in ]] && userpwd_in_str=":$username_in:$password_in" - kdump_install_net "$tgt_ipaddr" + kdump_collect_netif_usage "$tgt_ipaddr" # prepare netroot= command line # FIXME: Do we need to parse and set other parameters like protocol, port @@ -1097,7 +922,7 @@ kdump_configure_fence_kdump() { # setup network for each node for node in ${nodes}; do - kdump_install_net "$node" + kdump_collect_netif_usage "$node" done dracut_install /etc/hosts @@ -1208,6 +1033,8 @@ install() { inst "ip" fi + kdump_install_net + # For the lvm type target under kdump, in /etc/lvm/lvm.conf we can # safely replace "reserved_memory=XXXX"(default value is 8192) with # "reserved_memory=1024" to lower memory pressure under kdump. We do From 586fe410aa1b0093fb208c869b70ffeb7f085a55 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 9 Sep 2021 11:50:00 +0800 Subject: [PATCH 291/454] Reduce kdump memory consumption by not letting NetworkManager manage unneeded network interfaces By default, NetworkManger will manage all the network interfaces and try to set interface IFF_UP to get carrier state. Regardless of whether the network interface is connected to a cable or not, the NIC driver will allocate memory resources for e.g. ring buffers when setting IFF_UP. This could be a waste of memory. For example it's found i40e consumes ~15GB on a power machine. On this machine, i40e manages four interfaces but only one interface is valid. This patch use "managed=false" to tell NetworkManager to not manage network interfaces that are not needed by kdump by putting 10-kdump-netif_allowlist.conf in the initramfs. Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 67468cd..f4a026a 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -364,6 +364,29 @@ kdump_install_nmconnections() { echo > "${initdir}/usr/libexec/nm-initrd-generator" } +kdump_install_nm_netif_allowlist() { + local _netif _except_netif _netif_allowlist _netif_allowlist_nm_conf + + for _netif in $1; do + _per_mac=$(kdump_get_perm_addr "$_netif") + if [[ "$_per_mac" != 'not set' ]]; then + _except_netif="mac:$_per_mac" + else + _except_netif="interface-name:$_netif" + fi + _netif_allowlist="${_netif_allowlist}except:${_except_netif};" + done + + _netif_allowlist_nm_conf=$_DRACUT_KDUMP_NM_TMP_DIR/netif_allowlist_nm_conf + cat << EOF > "$_netif_allowlist_nm_conf" +[device-others] +match-device=${_netif_allowlist} +managed=false +EOF + + inst "$_netif_allowlist_nm_conf" "/etc/NetworkManager/conf.d/10-kdump-netif_allowlist.conf" +} + kdump_setup_bridge() { local _netdev=$1 local _dev @@ -558,6 +581,7 @@ kdump_install_net() { if [[ -n "$_netifs" ]]; then kdump_install_nmconnections apply_nm_initrd_generator_timeouts + kdump_install_nm_netif_allowlist "$_netifs" fi } From a65dde2d1083a57824aecd1840dea417c98c553d Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 19 May 2022 11:39:25 +0800 Subject: [PATCH 292/454] Reduce kdump memory consumption by only installing needed NIC drivers Even after having asked NM to stop managing a unneeded NIC, a NIC driver may still waste memory. For example, mlx5_core uses a substantial amount of memory during driver initialization, ======== Report format module_summary: ======== Module mlx5_core using 350.2MB (89650 pages), peak allocation 367.4MB (94056 pages) Module squashfs using 13.1MB (3360 pages), peak allocation 13.1MB (3360 pages) Module overlay using 2.1MB (550 pages), peak allocation 2.2MB (555 pages) Module dns_resolver using 0.9MB (219 pages), peak allocation 5.2MB (1338 pages) Module mlxfw using 0.7MB (172 pages), peak allocation 5.3MB (1349 pages) ======== Report format module_summary END ======== ======== Report format module_top: ======== Top stack usage of module mlx5_core: (null) Pages: 89650 (peak: 94056) ret_from_fork (0xffffda088b4165f8) Pages: 60007 (peak: 60007) kthread (0xffffda088b4bd7e4) Pages: 60007 (peak: 60007) worker_thread (0xffffda088b4b48d0) Pages: 60007 (peak: 60007) process_one_work (0xffffda088b4b3f40) Pages: 60007 (peak: 60007) work_for_cpu_fn (0xffffda088b4aef00) Pages: 53906 (peak: 53906) local_pci_probe (0xffffda088b9e1e44) Pages: 53906 (peak: 53906) probe_one mlx5_core (0xffffda084f899cc8) Pages: 53518 (peak: 53518) mlx5_init_one mlx5_core (0xffffda084f8994ac) Pages: 49756 (peak: 49756) mlx5_function_setup.constprop.0 mlx5_core (0xffffda084f899100) Pages: 44434 (eak: 44434) mlx5_satisfy_startup_pages mlx5_core (0xffffda084f8a4f24) Pages: 44434 (peak: 44434) mlx5_function_setup.constprop.0 mlx5_core (0xffffda084f899078) Pages: 5285 (peak: 5285) mlx5_cmd_init mlx5_core (0xffffda084f89e414) Pages: 4818 (peak: 4818) mlx5_alloc_cmd_msg mlx5_core (0xffffda084f89aaa0) Pages: 4403 (peak: 4403) This memory consumption is completely unnecessary when kdump doesn't need this NIC. Only install needed NIC drivers to prevent this kind of waste. Note 1. this patch depends on [1] to ask dracut to not install NIC drivers. 2. "ethtool -i" somehow fails to get the vlan driver 3. team.ko doesn't depend on the team mode drivers so we need to install the team mode drivers manually. [1] https://github.com/dracutdevs/dracut/pull/1789 Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 31 +++++++++++++++++++++++++++++++ mkdumprd | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index f4a026a..9ed8487 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -387,6 +387,36 @@ EOF inst "$_netif_allowlist_nm_conf" "/etc/NetworkManager/conf.d/10-kdump-netif_allowlist.conf" } +_get_nic_driver() { + ethtool -i "$1" | sed -n -E "s/driver: (.*)/\1/p" +} + +kdump_install_nic_driver() { + local _netif _driver _drivers + + _drivers=() + + for _netif in $1; do + _driver=$(_get_nic_driver "$_netif") + if [[ -z $_driver ]]; then + derror "Failed to get the driver of $_netif" + exit 1 + fi + + if [[ $_driver == "802.1Q VLAN Support" ]]; then + # ethtool somehow doesn't return the driver name for a VLAN NIC + _driver=8021q + elif [[ $_driver == "team" ]]; then + # install the team mode drivers like team_mode_roundrobin.ko as well + _driver='=drivers/net/team' + fi + + _drivers+=("$_driver") + done + + instmods "${_drivers[@]}" +} + kdump_setup_bridge() { local _netdev=$1 local _dev @@ -582,6 +612,7 @@ kdump_install_net() { kdump_install_nmconnections apply_nm_initrd_generator_timeouts kdump_install_nm_netif_allowlist "$_netifs" + kdump_install_nic_driver "$_netifs" fi } diff --git a/mkdumprd b/mkdumprd index 7b843a8..a069f92 100644 --- a/mkdumprd +++ b/mkdumprd @@ -27,7 +27,7 @@ SAVE_PATH=$(get_save_path) OVERRIDE_RESETTABLE=0 extra_modules="" -dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth resume ifcfg earlykdump") +dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict --hostonly-nics '' -o "plymouth resume ifcfg earlykdump") MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." From 568623e69a32266a3b00225b9de6a93435c44474 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 23 Sep 2021 14:25:01 +0800 Subject: [PATCH 293/454] Address the cases where a NIC has a different name in kdump kernel A NIC may get a different name in the kdump kernel from 1st kernel in cases like, - kernel assigned network interface names are not persistent e.g. [1] - there is an udev rule to rename the NIC in the 1st kernel but the kdump initrd may not have that rule e.g. [2] If NM tries to match a NIC with a connection profile based on NIC name i.e. connection.interface-name, it will fail the above bases. A simple solution is to ask NM to match a connection profile by MAC address. Note we don't need to do this for user-created NICs like vlan, bridge and bond. An remaining issue is passing the name of a NIC via the kdumpnic dracut command line parameter which requires passing ifname=: to have fixed NIC name. But we can simply drop this requirement. kdumpnic is needed because kdump needs to get the IP by NIC name and use the IP to created a dumping folder named "{IP}-{DATE}". We can simply pass the IP to the kdump kernel directly via a new dracut command line parameter kdumpip instead. In addition to the benefit of simplifying the code, there are other three benefits brought by this approach, - make use of whatever network to transfer the vmcore. Because as long as we have the network to we don't care which NIC is active. - if obtained IP in the kdump kernel is different from the one in the 1st kernel. "{IP}-{DATE}" would better tell where the dumped vmcore comes from. - without passing ifname=: to kdump initrd, the issue of there are two interfaces with the same MAC address for Azure Hyper-V NIC SR-IOV [3] is resolved automatically. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1121778 [2] https://bugzilla.redhat.com/show_bug.cgi?id=810107 [3] https://bugzilla.redhat.com/show_bug.cgi?id=1962421 Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-kdump.sh | 39 ++++++++++++++++------------- dracut-module-setup.sh | 57 +++++++++++++++--------------------------- kdump-lib-initramfs.sh | 14 +++++++++++ 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 9734f43..357c14c 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -484,25 +484,28 @@ save_vmcore_dmesg_ssh() get_host_ip() { - if is_nfs_dump_target || is_ssh_dump_target; then - kdumpnic=$(getarg kdumpnic=) - if [ -z "$kdumpnic" ]; then - derror "failed to get kdumpnic!" - return 1 - fi - if ! kdumphost=$(ip addr show dev "$kdumpnic" | grep '[ ]*inet'); then - derror "wrong kdumpnic: $kdumpnic" - return 1 - fi - kdumphost=$(echo "$kdumphost" | head -n 1 | awk '{print $2}') - kdumphost="${kdumphost%%/*}" - if [ -z "$kdumphost" ]; then - derror "wrong kdumpnic: $kdumpnic" - return 1 - fi - HOST_IP=$kdumphost + + if ! is_nfs_dump_target && ! is_ssh_dump_target; then + return 0 fi - return 0 + + _kdump_remote_ip=$(getarg kdump_remote_ip=) + + if [ -z "$_kdump_remote_ip" ]; then + derror "failed to get remote IP address!" + return 1 + fi + _route=$(kdump_get_ip_route "$_kdump_remote_ip") + _netdev=$(kdump_get_ip_route_field "$_route" "dev") + + if ! _kdumpip=$(ip addr show dev "$_netdev" | grep '[ ]*inet'); then + derror "Failed to get IP of $_netdev" + return 1 + fi + + _kdumpip=$(echo "$_kdumpip" | head -n 1 | awk '{print $2}') + _kdumpip="${_kdumpip%%/*}" + HOST_IP=$_kdumpip } read_kdump_confs() diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 9ed8487..2ecd99c 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -237,26 +237,6 @@ kdump_get_perm_addr() { fi } -# Prefix kernel assigned names with "kdump-". EX: eth0 -> kdump-eth0 -# Because kernel assigned names are not persistent between 1st and 2nd -# kernel. We could probably end up with eth0 being eth1, eth0 being -# eth1, and naming conflict happens. -kdump_setup_ifname() { - local _ifname - - # If ifname already has 'kdump-' prefix, we must be switching from - # fadump to kdump. Skip prefixing 'kdump-' in this case as adding - # another prefix may truncate the ifname. Since an ifname with - # 'kdump-' is already persistent, this should be fine. - if [[ $1 =~ eth* ]] && [[ ! $1 =~ ^kdump-* ]]; then - _ifname="kdump-$1" - else - _ifname="$1" - fi - - echo "$_ifname" -} - apply_nm_initrd_generator_timeouts() { local _timeout_conf @@ -304,6 +284,19 @@ _clone_nmconnection() { return 1 } +_match_nmconnection_by_mac() { + local _unique_id _dev _mac _mac_field + + _unique_id=$1 + _dev=$2 + + _mac=$(kdump_get_perm_addr "$_dev") + [[ $_mac != 'not set' ]] || return + _mac_field=$(nmcli --get-values connection.type connection show "$_unique_id").mac-address + nmcli connection modify --temporary "$_unique_id" "$_mac_field" "$_mac" &> >(ddebug) + nmcli connection modify --temporary "$_unique_id" "connection.interface-name" "" &> >(ddebug) +} + # Clone and modify NM connection profiles # # This function makes use of "nmcli clone" to automatically convert ifcfg-* @@ -325,6 +318,10 @@ clone_and_modify_nmconnection() { use_ipv4_or_ipv6 "$_dev" "$_uuid" nmcli connection modify --temporary uuid "$_uuid" connection.wait-device-timeout 60000 &> >(ddebug) + # For physical NIC i.e. non-user created NIC, ask NM to match a + # connection profile based on MAC address + _match_nmconnection_by_mac "$_uuid" "$_dev" + _cloned_nmconnection_file_path=$(nmcli --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p") _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename "$_nmconnection_file_path") cp "$_cloned_nmconnection_file_path" "$_tmp_nmconnection_file_path" @@ -528,19 +525,6 @@ kdump_setup_znet() { echo "rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS}" > "${initdir}/etc/cmdline.d/30znet.conf" } -kdump_get_ip_route() { - local _route - if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then - derror "Bad kdump network destination: $1" - exit 1 - fi - echo "$_route" -} - -kdump_get_ip_route_field() { - echo "$1" | sed -n -e "s/^.*\<$2\>\s\+\(\S\+\).*$/\1/p" -} - kdump_get_remote_ip() { local _remote _remote_temp _remote=$(get_remote_host "$1") @@ -557,14 +541,13 @@ kdump_get_remote_ip() { # Collect netifs needed by kdump # $1: destination host kdump_collect_netif_usage() { - local _destaddr _srcaddr _route _netdev kdumpnic + local _destaddr _srcaddr _route _netdev local _znet_netdev _znet_conpath _destaddr=$(kdump_get_remote_ip "$1") _route=$(kdump_get_ip_route "$_destaddr") _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") - kdumpnic=$(kdump_setup_ifname "$_netdev") _znet_netdev=$(find_online_znet_device) if [[ -n $_znet_netdev ]]; then @@ -591,8 +574,8 @@ kdump_collect_netif_usage() { echo "rd.neednet" >> "${initdir}/etc/cmdline.d/50neednet.conf" fi - if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpnic.conf ]]; then - echo "kdumpnic=$kdumpnic" > "${initdir}/etc/cmdline.d/60kdumpnic.conf" + if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpip.conf ]]; then + echo "kdump_remote_ip=$_destaddr" > "${initdir}/etc/cmdline.d/60kdumpip.conf" fi if is_ipv6_address "$_srcaddr"; then diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index a893532..e45d6de 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -163,3 +163,17 @@ is_lvm2_thinp_device() [ -n "$_lvm2_thin_device" ] } + +kdump_get_ip_route() +{ + if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then + derror "Bad kdump network destination: $1" + exit 1 + fi + echo "$_route" +} + +kdump_get_ip_route_field() +{ + echo "$1" | sed -n -e "s/^.*\<$2\>\s\+\(\S\+\).*$/\1/p" +} From 9792994f2f13dd7d6561140fe4b590114a8571c1 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 22 Sep 2022 22:31:47 +0800 Subject: [PATCH 294/454] Wait for the network to be truly ready before dumping vmcore nm-wait-online-initrd.service installed by dracut's 35-networkmanager module calls nm-online with "-s" which means it returns immediately when NetworkManager logs "startup complete". Thus it doesn't truly wait for network connectivity to be established [1]. Wait for the network to be truly ready before dumping vmcore. There are two benefits brought by this approach, - ssh/nfs dumping won't fail because of that the network is not ready e.g. [2][3] - users don't need to use workarounds like rd.net.carrier.timeout to make sure the network is ready [1] https://bugzilla.redhat.com/show_bug.cgi?id=1485712 [2] https://bugzilla.redhat.com/show_bug.cgi?id=1909014 [3] https://bugzilla.redhat.com/show_bug.cgi?id=2035451 Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-kdump.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 357c14c..4eec70b 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -482,6 +482,26 @@ save_vmcore_dmesg_ssh() fi } +wait_online_network() +{ + # In some cases, network may still not be ready because nm-online is called + # with "-s" which means to wait for NetworkManager startup to complete, rather + # than waiting for network connectivity specifically. Wait 10mins more for the + # network to be truely ready in these cases. + _loop=0 + while [ $_loop -lt 600 ]; do + sleep 1 + _loop=$((_loop + 1)) + if _route=$(kdump_get_ip_route "$1" 2> /dev/null); then + printf "%s" "$_route" + return + fi + done + + derror "Oops. The network still isn't ready after waiting 10mins." + exit 1 +} + get_host_ip() { @@ -495,7 +515,11 @@ get_host_ip() derror "failed to get remote IP address!" return 1 fi - _route=$(kdump_get_ip_route "$_kdump_remote_ip") + + if ! _route=$(wait_online_network "$_kdump_remote_ip"); then + return 1 + fi + _netdev=$(kdump_get_ip_route_field "$_route" "dev") if ! _kdumpip=$(ip addr show dev "$_netdev" | grep '[ ]*inet'); then From b5577c163aff88c458d638eb7954a000f6513ddb Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 23 Sep 2021 15:26:00 +0800 Subject: [PATCH 295/454] Simplify setup_znet by copying connection profile to initrd /usr/lib/udev/ccw_init [1] shipped by s390utils extracts the values of SUBCHANNELS, NETTYPE and LAYER2 from /etc/sysconfig/network-scripts/ifcfg-* or /etc/NetworkManager/system-connections/*.nmconnection to activate znet network device. If the connection profile is copied to initrd, there is no need to set up the "rd.znet" dracut cmdline parameter. There are two cases addressed by this commit, 1. znet network interface is a slave of bonding/teaming/vlan/bridging network. The connection profile has been copied to initrd by kdump_copy_nmconnection_file and it contains the info needed by ccw_init. 2. znet network interface is a slave of bonding/teaming/vlan/bridging network. The corresponding ifcfg-*/*.nmconnection file may not contain info like SUBCHANNELS [2]. In this case, copy the ifcfg-*/*.nmconnection file that has this info to the kdump initrd. Also to prevent the copied connection profile from being chosen by NM, set connection.autoconnect=false for this connection profile. With this implementation, there is also no need to check if znet is used beforehand. Note 1. ccw_init doesn't care if SUBCHANNELS, NETTYPE and LAYER2 comes from an active NM profile or not. If an inactive NM profile contains this info, it needs to be copied to the kdump initrd as well. 2. "rd.znet_ifname=$_netdev:${SUBCHANNELS}" is no longer needed needed because now there is no renaming of s390x network interfaces when reusing NetworkManager profiles. rd.znet_ifname was introduced in commit ce0305d ("Add a new option 'rd.znet_ifname' in order to use it in udev rules") to address the special case of non-persistent MAC address by renaming a network interface by SUBCHANNELS. [1] https://src.fedoraproject.org/rpms/s390utils/blob/rawhide/f/ccw_init [2] https://bugzilla.redhat.com/show_bug.cgi?id=2064708 Signed-off-by: Coiby Xu Reviewed-by: Thomas Haller Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 93 ++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 58 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 2ecd99c..0cac3bd 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -467,62 +467,48 @@ kdump_setup_vlan() { _save_kdump_netifs "$_parent_netif" } -# find online znet device -# return ifname (_netdev) -# code reaped from the list_configured function of -# https://github.com/hreinecke/s390-tools/blob/master/zconf/znetconf -find_online_znet_device() { - local CCWGROUPBUS_DEVICEDIR="/sys/bus/ccwgroup/devices" - local NETWORK_DEVICES d ifname ONLINE - - [[ ! -d $CCWGROUPBUS_DEVICEDIR ]] && return - NETWORK_DEVICES=$(find $CCWGROUPBUS_DEVICEDIR) - for d in $NETWORK_DEVICES; do - [[ ! -f "$d/online" ]] && continue - read -r ONLINE < "$d/online" - if [[ $ONLINE -ne 1 ]]; then - continue - fi - # determine interface name, if there (only for qeth and if - # device is online) - if [[ -f $d/if_name ]]; then - read -r ifname < "$d/if_name" - elif [[ -d $d/net ]]; then - ifname=$(ls "$d/net/") - fi - [[ -n $ifname ]] && break - done - echo -n "$ifname" +_find_znet_nmconnection() { + LANG=C grep -s -E -i -l \ + "^s390-subchannels=([0-9]\.[0-9]\.[a-f0-9]+;){0,2}" \ + "$1"/*.nmconnection | LC_ALL=C sed -e "$2" } -# setup s390 znet cmdline -# $1: netdev (ifname) -# $2: nmcli connection path +# setup s390 znet +# +# Note part of code is extracted from ccw_init provided by s390utils kdump_setup_znet() { - local _netdev="$1" - local _conpath="$2" - local s390_prefix="802-3-ethernet.s390-" - local _options="" - local NETTYPE - local SUBCHANNELS + local _config_file _unique_name _NM_conf_dir + local __sed_discard_ignored_files='/\(~\|\.bak\|\.old\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' - NETTYPE=$(get_nmcli_field_by_conpath "${s390_prefix}nettype" "$_conpath") - SUBCHANNELS=$(get_nmcli_field_by_conpath "${s390_prefix}subchannels" "$_conpath") - _options=$(get_nmcli_field_by_conpath "${s390_prefix}options" "$_conpath") - - if [[ -z $NETTYPE || -z $SUBCHANNELS || -z $_options ]]; then - dwarning "Failed to get znet configuration via nmlci output. Now try sourcing ifcfg script." - source_ifcfg_file "$_netdev" - for i in $OPTIONS; do - _options=${_options},$i - done + if [[ "$(uname -m)" != "s390x" ]]; then + return fi - if [[ -z $NETTYPE || -z $SUBCHANNELS || -z $_options ]]; then - exit 1 + _NM_conf_dir="/etc/NetworkManager/system-connections" + + _config_file=$(_find_znet_nmconnection "$initdir/$_NM_conf_dir" "$__sed_discard_ignored_files") + if [[ -n "$_config_file" ]]; then + ddebug "$_config_file has already contained the znet config" + return + fi + + _config_file=$(LANG=C grep -s -E -i -l \ + "^[[:space:]]*SUBCHANNELS=['\"]?([0-9]\.[0-9]\.[a-f0-9]+,){0,2}" \ + /etc/sysconfig/network-scripts/ifcfg-* \ + | LC_ALL=C sed -e "$__sed_discard_ignored_files") + + if [[ -z "$_config_file" ]]; then + _config_file=$(_find_znet_nmconnection "$_NM_conf_dir" "$__sed_discard_ignored_files") + fi + + if [[ -n "$_config_file" ]]; then + _unique_name=$(cat /proc/sys/kernel/random/uuid) + nmcli connection clone --temporary "$_config_file" "$_unique_name" &> >(ddebug) + nmcli connection modify --temporary "$_unique_name" connection.autoconnect false + inst "/run/NetworkManager/system-connections/${_unique_name}.nmconnection" "${_NM_conf_dir}/${_unique_name}.nmconnection" + nmcli connection del "$_unique_name" &> >(ddebug) fi - echo "rd.znet=${NETTYPE},${SUBCHANNELS},${_options} rd.znet_ifname=$_netdev:${SUBCHANNELS}" > "${initdir}/etc/cmdline.d/30znet.conf" } kdump_get_remote_ip() { @@ -542,22 +528,12 @@ kdump_get_remote_ip() { # $1: destination host kdump_collect_netif_usage() { local _destaddr _srcaddr _route _netdev - local _znet_netdev _znet_conpath _destaddr=$(kdump_get_remote_ip "$1") _route=$(kdump_get_ip_route "$_destaddr") _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") - _znet_netdev=$(find_online_znet_device) - if [[ -n $_znet_netdev ]]; then - _znet_conpath=$(get_nmcli_connection_apath_by_ifname "$_znet_netdev") - if ! (kdump_setup_znet "$_znet_netdev" "$_znet_conpath"); then - derror "Failed to set up znet" - exit 1 - fi - fi - if kdump_is_bridge "$_netdev"; then kdump_setup_bridge "$_netdev" elif kdump_is_bond "$_netdev"; then @@ -594,6 +570,7 @@ kdump_install_net() { if [[ -n "$_netifs" ]]; then kdump_install_nmconnections apply_nm_initrd_generator_timeouts + kdump_setup_znet kdump_install_nm_netif_allowlist "$_netifs" kdump_install_nic_driver "$_netifs" fi From 523cda8f343b1a48799a5c25e1d76a2a475a6b1d Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 25 Nov 2022 12:07:25 +0800 Subject: [PATCH 296/454] Don't run kdump_check_setup_iscsi in a subshell in order to collect needed network interfaces Currently, dumping to iSCSI target fails because the global array (unique_netifs) that stores the network interfaces needed by kdump is empty. The root cause is change of the array made in a subshell (a child process) is inaccessible to the parent process. So don't run kdump_check_setup_iscsi in a subshell. Fixes: 63c3805c ("Set up kdump network by directly copying NM connection profile to initrd") Signed-off-by: Coiby Xu Reviewed-by: Pingfan Liu --- dracut-module-setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 0cac3bd..1fa2a78 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -809,7 +809,7 @@ kdump_check_iscsi_targets() { # If our prerequisites are not met, fail anyways. type -P iscsistart > /dev/null || return 1 - kdump_check_setup_iscsi() ( + kdump_check_setup_iscsi() { local _dev _dev=$1 @@ -819,7 +819,7 @@ kdump_check_iscsi_targets() { cd .. done [[ -d iscsi_session ]] && kdump_setup_iscsi_device "$PWD" - ) + } [[ $hostonly ]] || [[ $mount_needs ]] && { for_each_host_dev_and_slaves_all kdump_check_setup_iscsi From 787b041aabd90ff2bf8fe6cc4d225032efde24d0 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 15 Nov 2022 12:00:09 +0800 Subject: [PATCH 297/454] kdump.conf: use a simple generator script to maintain This commit has the same motivation as the commit 677da8a "sysconfig: use a simple generator script to maintain". At present, only the kdump.conf generated for s390x has a slight difference from the other arches, where the core_collector asks the makedumpfile to use "-c" option to compress dump data by each page using zlib, which is more efficient than lzo on s390x. Signed-off-by: Pingfan Liu Reviewed-by: Philipp Rudo --- kdump.conf => gen-kdump-conf.sh | 37 +++++++++++++++++++++++++++++++++ kexec-tools.spec | 5 +++-- 2 files changed, 40 insertions(+), 2 deletions(-) rename kdump.conf => gen-kdump-conf.sh (95%) mode change 100644 => 100755 diff --git a/kdump.conf b/gen-kdump-conf.sh old mode 100644 new mode 100755 similarity index 95% rename from kdump.conf rename to gen-kdump-conf.sh index e598a49..a9f124f --- a/kdump.conf +++ b/gen-kdump-conf.sh @@ -1,3 +1,11 @@ +#!/bin/bash +# $1: target arch + +SED_EXP="" + +generate() +{ + sed "$SED_EXP" << EOF # This file contains a series of commands to perform (in order) in the kdump # kernel after a kernel crash in the crash kernel(1st kernel) has happened. # @@ -192,3 +200,32 @@ core_collector makedumpfile -l --message-level 7 -d 31 #dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3" #fence_kdump_args -p 7410 -f auto -c 0 -i 10 #fence_kdump_nodes node1 node2 +EOF +} + +update_param() +{ + SED_EXP="${SED_EXP}s/^$1.*$/$1 $2/;" +} + +case "$1" in +aarch64) ;; + +i386) ;; + +ppc64) ;; + +ppc64le) ;; + +s390x) + update_param core_collector \ + "makedumpfile -c --message-level 7 -d 31" + ;; +x86_64) ;; + +*) + echo "Warning: Unknown architecture '$1', using default kdump.conf template." + ;; +esac + +generate diff --git a/kexec-tools.spec b/kexec-tools.spec index bfa7a5b..cc62984 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -12,8 +12,8 @@ Summary: The kexec/kdump userspace component Source0: http://kernel.org/pub/linux/utils/kernel/kexec/%{name}-%{version}.tar.xz Source1: kdumpctl Source3: gen-kdump-sysconfig.sh +Source4: gen-kdump-conf.sh Source7: mkdumprd -Source8: kdump.conf Source9: https://github.com/makedumpfile/makedumpfile/archive/%{mkdf_ver}/makedumpfile-%{mkdf_shortver}.tar.gz Source10: kexec-kdump-howto.txt Source11: fadump-howto.txt @@ -147,6 +147,7 @@ cp %{SOURCE34} . # Generate sysconfig file %{SOURCE3} %{_target_cpu} > kdump.sysconfig +%{SOURCE4} %{_target_cpu} > kdump.conf make %ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 @@ -180,7 +181,7 @@ install -m 644 build/man/man8/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/ install -m 644 build/man/man8/vmcore-dmesg.8 $RPM_BUILD_ROOT%{_mandir}/man8/ install -m 755 %{SOURCE7} $RPM_BUILD_ROOT/usr/sbin/mkdumprd -install -m 644 %{SOURCE8} $RPM_BUILD_ROOT%{_sysconfdir}/kdump.conf +install -m 644 kdump.conf $RPM_BUILD_ROOT%{_sysconfdir}/kdump.conf install -m 644 kdump.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/kdump install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8 install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8 From 0414386cb827652082326e3b8a654bdc0f3d8571 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Fri, 25 Nov 2022 16:40:49 +0800 Subject: [PATCH 298/454] unit tests: adapt check_config to gen-kdump-conf.sh Now, kdump.conf is generated by gen-kdump-conf.sh, hence adapting check_config to run that script firstly then check the generated file. Signed-off-by: Pingfan Liu Reviewed-by: Coiby Xu --- spec/kdumpctl_general_spec.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index 5a3ce1c..41fbc29 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -178,6 +178,7 @@ Describe 'kdumpctl' bad_kdump_conf=$(mktemp -t bad_kdump_conf.XXXXXXXXXX) cleanup() { rm -f "$bad_kdump_conf" + rm -f kdump.conf } AfterAll 'cleanup' @@ -189,8 +190,11 @@ Describe 'kdumpctl' The stderr should include 'Invalid kdump config option blabla' End + Parameters:value aarch64 ppc64le s390x x86_64 + It 'should be happy with the default kdump.conf' - # shellcheck disable=SC2034 + ./gen-kdump-conf.sh "$1" > kdump.conf + # shellcheck disable=SC2034 # override the KDUMP_CONFIG_FILE variable KDUMP_CONFIG_FILE=./kdump.conf When call parse_config From 5eb77ee3fa986f39bb74a5956910aed6f60b8008 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Thu, 24 Nov 2022 09:15:25 +0800 Subject: [PATCH 299/454] kdumpctl: Optimize _find_kernel_path_by_release regex string Currently _find_kernel_path_by_release uses grubby and grep to find the kernel path, if both the normal kernel and it's debug varient exist, the grep will give more than one kernel strings. ``` kernel="/boot/vmlinuz-5.14.0-139.kpq0.el9.s390x+debug" kernel="/boot/vmlinuz-5.14.0-139.kpq0.el9.s390x" ``` This will cause an error when installing debug kernel. ``` The param "/boot/vmlinuz-5.14.0-139.kpq0.el9.s390x+debug /boot/vmlinuz-5.14.0-139.kpq0.el9.s390x" is incorrect ``` Fixes: 945cbbd ("add helper functions to get kernel path by kernel release and the path of current running kernel") Signed-off-by: Lichen Liu Reviewed-by: Philipp Rudo --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index b82d869..abfb352 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1353,7 +1353,7 @@ _filter_grubby_kernel_str() _find_kernel_path_by_release() { local _release="$1" _grubby_kernel_str _kernel_path - _grubby_kernel_str=$(grubby --info ALL | grep "^kernel=.*$_release") + _grubby_kernel_str=$(grubby --info ALL | grep "^kernel=.*$_release\"$") _kernel_path=$(_filter_grubby_kernel_str "$_grubby_kernel_str") if [[ -z $_kernel_path ]]; then derror "kernel $_release doesn't exist" From e96e441b36d1197c11832114d5e8c22d7c72d513 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 25 Nov 2022 17:47:20 +0800 Subject: [PATCH 300/454] Release 2.0.25-3 Signed-off-by: Coiby Xu --- kexec-tools.spec | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index cc62984..ec8cc68 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.25 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -414,7 +414,34 @@ fi %endif %changelog -* Thu Oct 27 2022 Coiby - 2.0.25-1 +* Fri Nov 25 2022 Coiby - 2.0.25-3 +- kdumpctl: Optimize _find_kernel_path_by_release regex string +- unit tests: adapt check_config to gen-kdump-conf.sh +- kdump.conf: use a simple generator script to maintain +- Don't run kdump_check_setup_iscsi in a subshell in order to collect needed network interfaces +- Simplify setup_znet by copying connection profile to initrd +- Wait for the network to be truly ready before dumping vmcore +- Address the cases where a NIC has a different name in kdump kernel +- Reduce kdump memory consumption by only installing needed NIC drivers +- Reduce kdump memory consumption by not letting NetworkManager manage unneeded network interfaces +- Set up kdump network by directly copying NM connection profile to initrd +- Stop dracut 35network-manager from running nm-initrd-generator +- Apply the timeout configuration of nm-initrd-generator +- Determine whether IPv4 or IPv6 is needed +- Add functions to copy NetworkManage connection profiles to the initramfs +- Fix error for vlan over team network interface +- Skip reset_crashkernel_after_update during package install +- Don't check fs modified when dump target is lvm2 thinp +- tests: use .nmconnection to set up test network +- fadump: preserve file modification time to help with hardlinking +- fadump: do not use squash to reduce image size +- selftest: Add lvm2 thin provision for kdump test +- selftest: Only iterate the .sh files for test execution +- Add dependency of dracut lvmthinpool-monitor module +- lvm.conf should be check modified if lvm2 thinp enabled +- Add lvm2 thin provision dump target checker + +* Thu Oct 27 2022 Coiby - 2.0.25-2 - Update makedumpfile to 1.7.2 - Skip reading /etc/defaut/grub for s390x - Include the memory overhead cost of cryptsetup when estimating the memory requirement for LUKS-encrypted target From f98bd5895e74043430b927828b0bd6944073e0cd Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Fri, 2 Dec 2022 18:46:49 +0530 Subject: [PATCH 301/454] fadump: use 'zstd' as the default compression method If available, use 'zstd' compression method to optimize the size of the initrd built with fadump support. Also, 'squash+zstd' is not preferred because more disk space is consumed with 'squash+zstd' due to the additional binaries needed for fadump with squash case. Signed-off-by: Hari Bathini Acked-by: Tao Liu Reviewed-by: Philipp Rudo --- mkfadumprd | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mkfadumprd b/mkfadumprd index 36ad645..2fc396c 100644 --- a/mkfadumprd +++ b/mkfadumprd @@ -62,11 +62,9 @@ _dracut_isolate_args=( /usr/lib/dracut/fadump-kernel-modules.txt ) -# Same as setting zstd in mkdumprd +# Use zstd compression method, if available if ! have_compression_in_dracut_args; then - if is_squash_available && dracut_have_option "--squash-compressor"; then - _dracut_isolate_args+=(--squash-compressor zstd) - elif is_zstd_command_available; then + if is_zstd_command_available; then _dracut_isolate_args+=(--compress zstd) fi fi From 25411da9660e732a53e675936813aad924ba65df Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Fri, 2 Dec 2022 18:46:50 +0530 Subject: [PATCH 302/454] fadump: fix default initrd backup and restore logic In case of fadump, default initrd is rebuilt with dump capturing capability, as the same initrd is used for booting production kernel as well as capture kernel. The original initrd file is backed up with a checksum, to restore it as the default initrd when fadump is disabled. As the checksum file is not kernel version specific, switching between different kernel versions and kdump/fadump dump mode breaks the default initrd backup/restore logic. Fix this by having a kernel version specific checksum file. Also, if backing up initrd fails, retaining the checksum file isn't useful. Remove it. Signed-off-by: Hari Bathini Reviewed-by: Philipp Rudo --- kdumpctl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index abfb352..af93202 100755 --- a/kdumpctl +++ b/kdumpctl @@ -9,9 +9,9 @@ KDUMP_LOG_PATH="/var/log" MKDUMPRD="/sbin/mkdumprd -f" MKFADUMPRD="/sbin/mkfadumprd" DRACUT_MODULES_FILE="/usr/lib/dracut/modules.txt" -INITRD_CHECKSUM_LOCATION="/boot/.fadump_initrd_checksum" DEFAULT_INITRD="" DEFAULT_INITRD_BAK="" +INITRD_CHECKSUM_LOCATION="" KDUMP_INITRD="" TARGET_INITRD="" FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" @@ -166,7 +166,8 @@ backup_default_initrd() sha1sum "$DEFAULT_INITRD" > "$INITRD_CHECKSUM_LOCATION" if ! cp "$DEFAULT_INITRD" "$DEFAULT_INITRD_BAK"; then dwarn "WARNING: failed to backup $DEFAULT_INITRD." - rm -f "$DEFAULT_INITRD_BAK" + rm -f -- "$INITRD_CHECKSUM_LOCATION" + rm -f -- "$DEFAULT_INITRD_BAK" fi fi } @@ -317,6 +318,7 @@ setup_initrd() fi DEFAULT_INITRD_BAK="$KDUMP_BOOTDIR/.$(basename "$DEFAULT_INITRD").default" + INITRD_CHECKSUM_LOCATION="$DEFAULT_INITRD_BAK.checksum" if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then TARGET_INITRD="$DEFAULT_INITRD" From 4a2dcab26ac5ede266449515fc906687728f9ace Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Fri, 2 Dec 2022 18:46:51 +0530 Subject: [PATCH 303/454] fadump: add a kernel install hook to clean up fadump initramfs Kdump service will create fadump initramfs when needed, but it won't clean up the fadump initramfs on kernel uninstall. So create a kernel install hook to do the clean up job. Signed-off-by: Hari Bathini Reviewed-by: Philipp Rudo --- 60-fadump.install | 31 +++++++++++++++++++++++++++++++ kexec-tools.spec | 3 +++ 2 files changed, 34 insertions(+) create mode 100755 60-fadump.install diff --git a/60-fadump.install b/60-fadump.install new file mode 100755 index 0000000..75318ff --- /dev/null +++ b/60-fadump.install @@ -0,0 +1,31 @@ +#!/usr/bin/bash + +COMMAND="$1" +KERNEL_VERSION="$2" + +if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then + exit 0 +fi + +# Currently, fadump is supported only in environments with +# writable /boot directory. +if [[ ! -w "/boot" ]]; then + exit 0 +fi + +FADUMP_INITRD="/boot/.initramfs-${KERNEL_VERSION}.img.default" +FADUMP_INITRD_CHECKSUM="$FADUMP_INITRD.checksum" + +ret=0 +case "$COMMAND" in + add) + # Do nothing, fadump initramfs is strictly host only + # and managed by kdump service + ;; + remove) + rm -f -- "$FADUMP_INITRD" + rm -f -- "$FADUMP_INITRD_CHECKSUM" + ret=$? + ;; +esac +exit $ret diff --git a/kexec-tools.spec b/kexec-tools.spec index ec8cc68..e863e7c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -38,6 +38,7 @@ Source33: 92-crashkernel.install Source34: crashkernel-howto.txt Source35: kdump-migrate-action.sh Source36: kdump-restart.sh +Source37: 60-fadump.install ####################################### # These are sources for mkdumpramfs @@ -204,6 +205,7 @@ install -m 644 %{SOURCE13} $RPM_BUILD_ROOT%{_udevrulesdir}/98-kexec.rules %endif %ifarch ppc64 ppc64le install -m 644 %{SOURCE14} $RPM_BUILD_ROOT%{_udevrulesdir}/98-kexec.rules +install -m 755 -D %{SOURCE37} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-fadump.install %endif install -m 644 %{SOURCE15} $RPM_BUILD_ROOT%{_mandir}/man5/kdump.conf.5 install -m 644 %{SOURCE16} $RPM_BUILD_ROOT%{_unitdir}/kdump.service @@ -366,6 +368,7 @@ fi %endif %ifarch ppc64 ppc64le /usr/sbin/mkfadumprd +%{_prefix}/lib/kernel/install.d/60-fadump.install %endif /usr/sbin/mkdumprd /usr/sbin/vmcore-dmesg From a833624fe57a28a4ccb44f7f27f06a7e867e8755 Mon Sep 17 00:00:00 2001 From: Hari Bathini Date: Mon, 21 Nov 2022 18:56:08 +0530 Subject: [PATCH 304/454] fadump: avoid status check while starting in fadump mode With kernel commit 607451ce0aa9b ("powerpc/fadump: register for fadump as early as possible"), 'kdumpctl start' prematurely returns with the below message: "Kdump already running: [WARNING]" instead of setting default initrd with dump capture capability as required for fadump. Skip status check in fadump mode to avoid this problem. Signed-off-by: Hari Bathini Reviewed-by: Philipp Rudo --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index af93202..3cad3dd 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1061,7 +1061,7 @@ start() return 1 fi - if check_current_status; then + if [[ $DEFAULT_DUMP_MODE == "kdump" ]] && check_current_kdump_status; then dwarn "Kdump already running: [WARNING]" return 0 fi From b45896c62096f7fcfd65afffb4cd93a3ae5f8b1a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 6 Dec 2022 18:18:32 +0800 Subject: [PATCH 305/454] dracut-module-setup.sh: stop overwriting dracut's trap handler Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2149246 Latest Workstation live x86_64 image has an excess increase of ~300 MB in size. This is because kdumpbase module's trap handler overwrites dracut's handler and DRACUT_TMPDIR which has three unpacked initramfs files fails to be cleaned up. This patch moves kdumpbase module's temporary folder under DRACUT_TMPDIR and lets dracut's trap handler do the cleanup instead. Fixes: d25b1ee3 ("Add functions to copy NetworkManage connection profiles to the initramfs") Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 1fa2a78..13e9901 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1,6 +1,6 @@ #!/bin/bash -_DRACUT_KDUMP_NM_TMP_DIR="/tmp/$$-DRACUT_KDUMP_NM" +_DRACUT_KDUMP_NM_TMP_DIR="$DRACUT_TMPDIR/$$-DRACUT_KDUMP_NM" _save_kdump_netifs() { unique_netifs[$1]=1 @@ -10,13 +10,6 @@ _get_kdump_netifs() { echo -n "${!unique_netifs[@]}" } -cleanup() { - rm -rf "$_DRACUT_KDUMP_NM_TMP_DIR" -} - -# shellcheck disable=SC2154 # known issue of shellcheck https://github.com/koalaman/shellcheck/issues/1299 -trap 'ret=$?; cleanup; exit $ret;' EXIT - kdump_module_init() { if ! [[ -d "${initdir}/tmp" ]]; then mkdir -p "${initdir}/tmp" From bc4196afc1a56babefb21dfa03c77f80f0dc369f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 7 Dec 2022 17:47:58 +0800 Subject: [PATCH 306/454] Release 2.0.25-4 Signed-off-by: Coiby Xu --- kexec-tools.spec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index e863e7c..24fad76 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.25 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -417,6 +417,13 @@ fi %endif %changelog +* Wed Dec 07 2022 Coiby - 2.0.25-4 +- dracut-module-setup.sh: stop overwriting dracut's trap handler +- fadump: avoid status check while starting in fadump mode +- fadump: add a kernel install hook to clean up fadump initramfs +- fadump: fix default initrd backup and restore logic +- fadump: use 'zstd' as the default compression method + * Fri Nov 25 2022 Coiby - 2.0.25-3 - kdumpctl: Optimize _find_kernel_path_by_release regex string - unit tests: adapt check_config to gen-kdump-conf.sh From 3b22cce1cb7dd12be07822018d08c9bb8f03add9 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 14 Dec 2022 10:12:17 +0800 Subject: [PATCH 307/454] dracut-module-setup.sh: skip installing driver for the loopback interface Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2151500 Currently, kdump initrd fails to be built when dumping vmcore to localhost via ssh or nfs, kdumpctl[3331]: Cannot get driver information: Operation not supported kdumpctl[1991]: dracut: Failed to get the driver of lo dracut[2020]: Failed to get the driver of lo kdumpctl[1775]: kdump: mkdumprd: failed to make kdump initrd kdumpctl[1775]: kdump: Starting kdump: [FAILED] systemd[1]: kdump.service: Main process exited, code=exited, status=1/FAILURE systemd[1]: kdump.service: Failed with result 'exit-code'. systemd[1]: Failed to start Crash recovery kernel arming. systemd[1]: kdump.service: Consumed 1.710s CPU time. This is because the loopback interface is used for transferring vmcore and ethtool can't get the driver of the loopback interface. In fact, once COFNIG_NET is enabled, the loopback device is enabled and there is no driver for the loopback device. So skip installing driver for the loopback device. The loopback interface is implemented in linux/drivers/net/loopback.c and always has the name "lo". So we can safely tell if a network interface is the loopback interface by its name. Fixes: a65dde2d ("Reduce kdump memory consumption by only installing needed NIC drivers") Reported-by: Martin Pitt Reported-by: Rich Megginson Reviewed-by: Lichen Liu Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- dracut-module-setup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 13e9901..fafaea0 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -387,6 +387,7 @@ kdump_install_nic_driver() { _drivers=() for _netif in $1; do + [[ $_netif == lo ]] && continue _driver=$(_get_nic_driver "$_netif") if [[ -z $_driver ]]; then derror "Failed to get the driver of $_netif" @@ -404,6 +405,7 @@ kdump_install_nic_driver() { _drivers+=("$_driver") done + [[ -n ${_drivers[*]} ]] || return instmods "${_drivers[@]}" } From bc101086e2c32594c8e01b50f0353f50d71f87f5 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 12 Dec 2022 18:37:25 +0800 Subject: [PATCH 308/454] dracut-module-setup.sh: also install the driver of physical NIC for Hyper-V VM with accelerated networking Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2151842 Currently, vmcore dumping to remote fs fails on Azure Hyper-V VM with accelerated networking because it uses a physical NIC for accrelarated networking [1]. In this case, the driver for this physical NIC should be installed as well. [1] https://learn.microsoft.com/en-us/azure/virtual-network/accelerated-networking-overview Fixes: a65dde2d ("Reduce kdump memory consumption by only installing needed NIC drivers") Reported-by: Xiaoqiang Xiong Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index fafaea0..a8ac16c 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -381,6 +381,14 @@ _get_nic_driver() { ethtool -i "$1" | sed -n -E "s/driver: (.*)/\1/p" } +_get_hpyerv_physical_driver() { + local _physical_nic + + _physical_nic=$(find /sys/class/net/"$1"/ -name 'lower_*' | sed -En "s/\/.*lower_(.*)/\1/p") + [[ -n $_physical_nic ]] || return + _get_nic_driver "$_physical_nic" +} + kdump_install_nic_driver() { local _netif _driver _drivers @@ -400,6 +408,11 @@ kdump_install_nic_driver() { elif [[ $_driver == "team" ]]; then # install the team mode drivers like team_mode_roundrobin.ko as well _driver='=drivers/net/team' + elif [[ $_driver == "hv_netvsc" ]]; then + # A Hyper-V VM may have accelerated networking + # https://learn.microsoft.com/en-us/azure/virtual-network/accelerated-networking-overview + # Install the driver of physical NIC as well + _drivers+=("$(_get_hpyerv_physical_driver "$_netif")") fi _drivers+=("$_driver") From 5951b5e26823b6bedf3237bd169a781b03f25031 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 20 Dec 2022 13:59:18 +0800 Subject: [PATCH 309/454] Don't try to update crashkernel when bootloader is not installed Currently when using anaconda to install the OS, the following errors occur, INF packaging: Configuring (running scriptlet for): kernel-core-5.14.0-70.el9.x86_64 ... INF dnf.rpm: grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory ... INF packaging: Configuring (running scriptlet for): kexec-tools-2.0.23-9.el9.x86_64 ... INF dnf.rpm: grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory grep: /boot/grub2/grubenv: No such file or directory Or for s390, the following errors occur, INF packaging: Configuring (running scriptlet for): kernel-core-5.14.0-71.el9.s390x ... 03:37:51,232 INF dnf.rpm: grep: /etc/zipl.conf: No such file or directory grep: /etc/zipl.conf: No such file or directory grep: /etc/zipl.conf: No such file or directory INF packaging: Configuring (running scriptlet for): kexec-tools-2.0.23-9_1.el9_0.s390x ... INF dnf.rpm: grep: /etc/zipl.conf: No such file or directory This is because when anaconda installs the packages, bootloader hasn't been installed and /boot/grub2/grubenv or /etc/zipl.conf doesn't exist. So don't try to update crashkernel when bootloader isn't ready to avoid the above errors. Note this is the second attempt to fix this issue. Previously a file /tmp/kexec_tools_package_install was created to avoid running the related code thus to avoid the above errors but unfortunately that approach has two issues a) somehow osbuild doesn't delete it for RHEL b) this file could still exist if users manually remove kexec-tools. Fixes: e218128 ("Only try to reset crashkernel for osbuild during package install") Reported-by: Jan Stodola Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdumpctl | 17 ++++++++--------- kexec-tools.spec | 5 ----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/kdumpctl b/kdumpctl index 3cad3dd..361bf51 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1611,10 +1611,13 @@ reset_crashkernel() fi } -# to tell if it's package install other than upgrade -_is_package_install() +_is_bootloader_installed() { - [[ -f /tmp/kexec_tools_package_install ]] + if [[ $(uname -r) == s390x ]]; then + test -f /etc/zipl.conf + else + test -f /boot/grub2/grub.cfg + fi } # update the crashkernel value in GRUB_ETC_DEFAULT if necessary @@ -1626,10 +1629,6 @@ update_crashkernel_in_grub_etc_default_after_update() local _crashkernel _fadump_val local _dump_mode _old_default_crashkernel _new_default_crashkernel - if _is_package_install; then - return - fi - if [[ $(uname -m) == s390x ]]; then return fi @@ -1659,7 +1658,7 @@ reset_crashkernel_after_update() local _kernel _crashkernel _dump_mode _fadump_val _old_default_crashkernel _new_default_crashkernel declare -A _crashkernel_vals - if _is_package_install; then + if ! _is_bootloader_installed; then return fi @@ -1715,7 +1714,7 @@ reset_crashkernel_for_installed_kernel() # During package install, only try to reset crashkernel for osbuild # thus to avoid calling grubby when installing os via anaconda - if _is_package_install && ! _is_osbuild; then + if ! _is_bootloader_installed && ! _is_osbuild; then return fi diff --git a/kexec-tools.spec b/kexec-tools.spec index 24fad76..1ee1770 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -268,11 +268,6 @@ if [ ! -f /run/ostree-booted ] && [ $1 == 2 ] && grep -q get-default-crashkernel kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null %endif fi -# indicate it's package install so kdumpctl later will only reset crashkernel -# value for osbuild. -if [ $1 == 1 ]; then - touch /tmp/kexec_tools_package_install -fi # don't block package update : From 4895f2a2e9bc2c6c3d274c5214990bb33f142574 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 22 Dec 2022 12:55:14 +0800 Subject: [PATCH 310/454] Release 2.0.26-1 Signed-off-by: Coiby Xu --- kexec-tools.spec | 10 ++++++++-- sources | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 1ee1770..ea49eb2 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,8 +4,8 @@ %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools -Version: 2.0.25 -Release: 4%{?dist} +Version: 2.0.26 +Release: 1%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -412,6 +412,12 @@ fi %endif %changelog +* Thu Dec 22 2022 Coiby - 2.0.26-1 +- Update kexec-tools to 2.0.25 +- Don't try to update crashkernel when bootloader is not installed +- dracut-module-setup.sh: also install the driver of physical NIC for Hyper-V VM with accelerated networking +- dracut-module-setup.sh: skip installing driver for the loopback interface + * Wed Dec 07 2022 Coiby - 2.0.25-4 - dracut-module-setup.sh: stop overwriting dracut's trap handler - fadump: avoid status check while starting in fadump mode diff --git a/sources b/sources index 20bacfe..d684233 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 -SHA512 (kexec-tools-2.0.25.tar.xz) = 6fd3fe11d428c5bb2ce318744146e03ddf752cc77632064bdd7418ef3ad355ad2e2db212d68a5bc73554d78f786901beb42d72bd62e2a4dae34fb224b667ec6b +SHA512 (kexec-tools-2.0.26.tar.xz) = afecb64f50a0a2e553712d7e6e4d48e0dc745e4140983a33a10cce931e6aeddaff9c4a3385fbaf7ab9ff7b3b905d932fbce1e0e37aa2c35d5c1e61277140dee9 SHA512 (makedumpfile-1.7.2.tar.gz) = 324e303dd5f507703f66e2bd5dc9d24f9f50ba797be70c05702008ba77078f61ffcc884796ddf9ab737de1d124c3a9d881ab5ce4f3f459690ec00055af25ea9e From 4ffc0113a6d1671e80884671eaf6f3a8ba2fed30 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Thu, 19 Jan 2023 14:23:04 +0000 Subject: [PATCH 311/454] Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index ea49eb2..bee8721 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -412,6 +412,9 @@ fi %endif %changelog +* Thu Jan 19 2023 Fedora Release Engineering - 2.0.26-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild + * Thu Dec 22 2022 Coiby - 2.0.26-1 - Update kexec-tools to 2.0.25 - Don't try to update crashkernel when bootloader is not installed From f4c04c3d6358ef7691fbf6a399d22739f1ebdb88 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 12 Jan 2023 15:02:55 +0800 Subject: [PATCH 312/454] makedumpfile: Fix wrong exclusion of slab pages on Linux 6.2-rc1 Resolves: bz2155754 Upstream: https://github.com/makedumpfile/makedumpfile Conflict: None commit 5f17bdd2128998a3eeeb4521d136a192222fadb6 Author: Kazuhito Hagio Date: Wed Dec 21 11:06:39 2022 +0900 [PATCH] Fix wrong exclusion of slab pages on Linux 6.2-rc1 * Required for kernel 6.2 Kernel commit 130d4df57390 ("mm/sl[au]b: rearrange struct slab fields to allow larger rcu_head"), which is contained in Linux 6.2-rc1 and later, made the offset of slab.slabs equal to page.mapping's one. As a result, "makedumpfile -d 8", which should exclude user data, excludes some slab pages wrongly because isAnon() returns true when slab.slabs is an odd number. With such dumpfiles, crash can fail to start session with an error like this: # crash vmlinux dumpfile ... crash: page excluded: kernel virtual address: ffff8fa047ac2fe8 type: "xa_node shift" Make isAnon() check that the page is not slab to fix this. Signed-off-by: Kazuhito Hagio Reported-by: Baoquan He Acked-by: Baoquan He Signed-off-by: Coiby Xu --- ...exclusion-of-slab-pages-on-Linux-6.2.patch | 81 +++++++++++++++++++ kexec-tools.spec | 2 + 2 files changed, 83 insertions(+) create mode 100644 kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch diff --git a/kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch b/kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch new file mode 100644 index 0000000..5d91bc2 --- /dev/null +++ b/kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch @@ -0,0 +1,81 @@ +From 5f17bdd2128998a3eeeb4521d136a192222fadb6 Mon Sep 17 00:00:00 2001 +From: Kazuhito Hagio +Date: Wed, 21 Dec 2022 11:06:39 +0900 +Subject: [PATCH] [PATCH] Fix wrong exclusion of slab pages on Linux 6.2-rc1 + +* Required for kernel 6.2 + +Kernel commit 130d4df57390 ("mm/sl[au]b: rearrange struct slab fields to +allow larger rcu_head"), which is contained in Linux 6.2-rc1 and later, +made the offset of slab.slabs equal to page.mapping's one. As a result, +"makedumpfile -d 8", which should exclude user data, excludes some slab +pages wrongly because isAnon() returns true when slab.slabs is an odd +number. With such dumpfiles, crash can fail to start session with an +error like this: + + # crash vmlinux dumpfile + ... + crash: page excluded: kernel virtual address: ffff8fa047ac2fe8 type: "xa_node shift" + +Make isAnon() check that the page is not slab to fix this. + +Signed-off-by: Kazuhito Hagio +--- + makedumpfile.c | 6 +++--- + makedumpfile.h | 9 +++------ + 2 files changed, 6 insertions(+), 9 deletions(-) + +diff --git a/makedumpfile-1.7.2/makedumpfile.c b/makedumpfile-1.7.2/makedumpfile.c +index ff821eb..f403683 100644 +--- a/makedumpfile-1.7.2/makedumpfile.c ++++ b/makedumpfile-1.7.2/makedumpfile.c +@@ -6502,7 +6502,7 @@ __exclude_unnecessary_pages(unsigned long mem_map, + */ + else if ((info->dump_level & DL_EXCLUDE_CACHE) + && is_cache_page(flags) +- && !isPrivate(flags) && !isAnon(mapping)) { ++ && !isPrivate(flags) && !isAnon(mapping, flags)) { + pfn_counter = &pfn_cache; + } + /* +@@ -6510,7 +6510,7 @@ __exclude_unnecessary_pages(unsigned long mem_map, + */ + else if ((info->dump_level & DL_EXCLUDE_CACHE_PRI) + && is_cache_page(flags) +- && !isAnon(mapping)) { ++ && !isAnon(mapping, flags)) { + if (isPrivate(flags)) + pfn_counter = &pfn_cache_private; + else +@@ -6522,7 +6522,7 @@ __exclude_unnecessary_pages(unsigned long mem_map, + * - hugetlbfs pages + */ + else if ((info->dump_level & DL_EXCLUDE_USER_DATA) +- && (isAnon(mapping) || isHugetlb(compound_dtor))) { ++ && (isAnon(mapping, flags) || isHugetlb(compound_dtor))) { + pfn_counter = &pfn_user; + } + /* +diff --git a/makedumpfile-1.7.2/makedumpfile.h b/makedumpfile-1.7.2/makedumpfile.h +index 70a1a91..21dec7d 100644 +--- a/makedumpfile-1.7.2/makedumpfile.h ++++ b/makedumpfile-1.7.2/makedumpfile.h +@@ -161,12 +161,9 @@ test_bit(int nr, unsigned long addr) + #define isSwapBacked(flags) test_bit(NUMBER(PG_swapbacked), flags) + #define isHWPOISON(flags) (test_bit(NUMBER(PG_hwpoison), flags) \ + && (NUMBER(PG_hwpoison) != NOT_FOUND_NUMBER)) +- +-static inline int +-isAnon(unsigned long mapping) +-{ +- return ((unsigned long)mapping & PAGE_MAPPING_ANON) != 0; +-} ++#define isSlab(flags) test_bit(NUMBER(PG_slab), flags) ++#define isAnon(mapping, flags) (((unsigned long)mapping & PAGE_MAPPING_ANON) != 0 \ ++ && !isSlab(flags)) + + #define PTOB(X) (((unsigned long long)(X)) << PAGESHIFT()) + #define BTOP(X) (((unsigned long long)(X)) >> PAGESHIFT()) +-- +2.39.0 + diff --git a/kexec-tools.spec b/kexec-tools.spec index bee8721..a413139 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -105,6 +105,7 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # +Patch601: kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -120,6 +121,7 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} +%patch601 -p1 %ifarch ppc %define archdef ARCH=ppc From d5faaee62b13857fc20a47dd2f1bd2642faa4658 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:30:59 +0100 Subject: [PATCH 313/454] kdumpctl: simplify check_failure_action_config With the deprecation of the 'default' option in kdump.conf check_failure_action_config needed to track which option was used (default or failure_action). This made the function quite complex.Thus make option 'default' a true alias of 'failure_action' when parsing kdump.conf and simplify check_failure_action_config. Do the same simplifications for check_final_action_config as both functions are basically identical. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 55 +++++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/kdumpctl b/kdumpctl index 361bf51..7e47091 100755 --- a/kdumpctl +++ b/kdumpctl @@ -255,7 +255,12 @@ parse_config() config_val=$DEFAULT_SSHKEY fi ;; - path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | default | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; + default) + dwarn "WARNING: Option 'default' was renamed 'failure_action' and will be removed in the future." + dwarn "Please update $KDUMP_CONFIG_FILE to use option 'failure_action' instead." + _set_config failure_action "$config_val" || return 1 + ;; + path | core_collector | kdump_post | kdump_pre | extra_bins | extra_modules | failure_action | final_action | force_rebuild | force_no_rebuild | fence_kdump_args | fence_kdump_nodes | auto_reset_crashkernel) ;; net | options | link_delay | disk_timeout | debug_mem_level | blacklist) derror "Deprecated kdump config option: $config_opt. Refer to kdump.conf manpage for alternatives." @@ -990,31 +995,12 @@ start_dump() check_failure_action_config() { - local default_option - local failure_action - local option="failure_action" - - default_option=${OPT[default]} - failure_action=${OPT[failure_action]} - - if [[ -z $failure_action ]] && [[ -z $default_option ]]; then - return 0 - elif [[ -n $failure_action ]] && [[ -n $default_option ]]; then - derror "Cannot specify 'failure_action' and 'default' option together" - return 1 - fi - - if [[ -n $default_option ]]; then - option="default" - failure_action="$default_option" - fi - - case "$failure_action" in - reboot | halt | poweroff | shell | dump_to_rootfs) + case "${OPT[failure_action]}" in + "" | reboot | halt | poweroff | shell | dump_to_rootfs) return 0 ;; *) - dinfo $"Usage kdump.conf: $option {reboot|halt|poweroff|shell|dump_to_rootfs}" + dinfo $"Usage kdump.conf: failure_action {reboot|halt|poweroff|shell|dump_to_rootfs}" return 1 ;; esac @@ -1022,22 +1008,15 @@ check_failure_action_config() check_final_action_config() { - local final_action - - final_action=${OPT[final_action]} - if [[ -z $final_action ]]; then + case "${OPT[final_action]}" in + "" | reboot | halt | poweroff) return 0 - else - case "$final_action" in - reboot | halt | poweroff) - return 0 - ;; - *) - dinfo $"Usage kdump.conf: final_action {reboot|halt|poweroff}" - return 1 - ;; - esac - fi + ;; + *) + dinfo $"Usage kdump.conf: final_action {reboot|halt|poweroff}" + return 1 + ;; + esac } start() From 0578245746a4324d8e6ff5d22824975f8998154e Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:00 +0100 Subject: [PATCH 314/454] dracut-early-kdump: fix shellcheck findings Fix the following issues found by shellcheck. For the second one disable shellcheck as EARLY_KEXEC_ARGS can contain multiple arguments. In dracut-early-kdump.sh line 9: EARLY_KDUMP_KERNELVER="" ^-------------------^ SC2034: EARLY_KDUMP_KERNELVER appears unused. Verify use (or export if used externally). In dracut-early-kdump.sh line 61: if $KEXEC $EARLY_KEXEC_ARGS $standard_kexec_args \ ^---------------^ SC2086: Double quote to prevent globbing and word splitting. For more information: https://www.shellcheck.net/wiki/SC2034 https://www.shellcheck.net/wiki/SC2086 Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- dracut-early-kdump.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh index 45ee6dc..3b84b48 100755 --- a/dracut-early-kdump.sh +++ b/dracut-early-kdump.sh @@ -6,7 +6,6 @@ standard_kexec_args="-p" EARLY_KDUMP_INITRD="" EARLY_KDUMP_KERNEL="" EARLY_KDUMP_CMDLINE="" -EARLY_KDUMP_KERNELVER="" EARLY_KEXEC_ARGS="" . /etc/sysconfig/kdump @@ -58,6 +57,7 @@ early_kdump_load() --command-line=$EARLY_KDUMP_CMDLINE --initrd=$EARLY_KDUMP_INITRD \ $EARLY_KDUMP_KERNEL" + # shellcheck disable=SC2086 if $KEXEC $EARLY_KEXEC_ARGS $standard_kexec_args \ --command-line="$EARLY_KDUMP_CMDLINE" \ --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL; then From ed6936f9fc9f56ee6a3e95acdea7ce1767b511dc Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:01 +0100 Subject: [PATCH 315/454] dracut-early-kdump: explicitly use bash Currently dracut-early-kdump.sh claims to be POSIX compliant but it sources kdump-lib.sh which uses bash-only syntax. Thus require bash for dracut-early-kdump.sh as well. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- .editorconfig | 2 +- dracut-early-kdump.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 87c4f98..b343f27 100644 --- a/.editorconfig +++ b/.editorconfig @@ -22,7 +22,7 @@ space_redirects = true shell_variant = bash # Use dracut code style for *-module-setup.sh -[*-module-setup.sh] +[*-module-setup.sh,dracut-early-kdump.sh] shell_variant = bash indent_style = space indent_size = 4 diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh index 3b84b48..f8d4e0f 100755 --- a/dracut-early-kdump.sh +++ b/dracut-early-kdump.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash KEXEC=/sbin/kexec standard_kexec_args="-p" From b9fd7a4076a2b355f57c7c2529a093f3aa9f6863 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:02 +0100 Subject: [PATCH 316/454] kdumpctl: merge check_current_{kdump,fadump}_status Both functions are almost identical. The only differences are (1) the sysfs node the status is read from and (2) the fact the fadump version doesn't verify if the file it's trying to read actually exists. Thus merge the two functions and get rid of the check_current_status wrapper. While at it rename the function to is_kernel_loaded which explains better what the function does. Finally, after moving FADUMP_REGISTER_SYS_NODE shellcheck can no longer access the definition and starts complaining about it not being quoted. Thus quote all uses of FADUMP_REGISTER_SYS_NODE. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- dracut-early-kdump.sh | 2 +- kdump-lib.sh | 31 ++++++++++++++++++++++--------- kdumpctl | 34 ++++++++-------------------------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh index f8d4e0f..044f741 100755 --- a/dracut-early-kdump.sh +++ b/dracut-early-kdump.sh @@ -37,7 +37,7 @@ early_kdump_load() return 1 fi - if check_current_kdump_status; then + if is_kernel_loaded "kdump"; then return 1 fi diff --git a/kdump-lib.sh b/kdump-lib.sh index 400b05c..c3091c8 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -9,6 +9,7 @@ else fi FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" +FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" is_fadump_capable() { @@ -494,19 +495,31 @@ check_kdump_feasibility() return $? } -check_current_kdump_status() +is_kernel_loaded() { - if [[ ! -f /sys/kernel/kexec_crash_loaded ]]; then - derror "Perhaps CONFIG_CRASH_DUMP is not enabled in kernel" + local _sysfs _mode + + _mode=$1 + + case "$_mode" in + kdump) + _sysfs="/sys/kernel/kexec_crash_loaded" + ;; + fadump) + _sysfs="$FADUMP_REGISTER_SYS_NODE" + ;; + *) + derror "Unknown dump mode '$_mode' provided" + return 1 + ;; + esac + + if [[ ! -f $_sysfs ]]; then + derror "$_mode is not supported on this kernel" return 1 fi - rc=$(< /sys/kernel/kexec_crash_loaded) - if [[ $rc == 1 ]]; then - return 0 - else - return 1 - fi + [[ $(< $_sysfs) -eq 1 ]] } # remove_cmdline_param [] ... [] diff --git a/kdumpctl b/kdumpctl index 7e47091..dd4bae6 100755 --- a/kdumpctl +++ b/kdumpctl @@ -14,7 +14,6 @@ DEFAULT_INITRD_BAK="" INITRD_CHECKSUM_LOCATION="" KDUMP_INITRD="" TARGET_INITRD="" -FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" #kdump shall be the default dump mode DEFAULT_DUMP_MODE="kdump" image_time=0 @@ -837,23 +836,6 @@ show_reserved_mem() dinfo "Reserved ${mem_mb}MB memory for crash kernel" } -check_current_fadump_status() -{ - # Check if firmware-assisted dump has been registered. - rc=$(< $FADUMP_REGISTER_SYS_NODE) - [[ $rc -eq 1 ]] && return 0 - return 1 -} - -check_current_status() -{ - if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then - check_current_fadump_status - else - check_current_kdump_status - fi -} - save_raw() { local raw_target @@ -974,8 +956,8 @@ check_dump_feasibility() start_fadump() { - echo 1 > $FADUMP_REGISTER_SYS_NODE - if ! check_current_fadump_status; then + echo 1 > "$FADUMP_REGISTER_SYS_NODE" + if ! is_kernel_loaded "fadump"; then derror "fadump: failed to register" return 1 fi @@ -1040,7 +1022,7 @@ start() return 1 fi - if [[ $DEFAULT_DUMP_MODE == "kdump" ]] && check_current_kdump_status; then + if [[ $DEFAULT_DUMP_MODE == "kdump" ]] && is_kernel_loaded "kdump"; then dwarn "Kdump already running: [WARNING]" return 0 fi @@ -1065,7 +1047,7 @@ start() reload() { - if ! check_current_status; then + if ! is_kernel_loaded "$DEFAULT_DUMP_MODE"; then dwarn "Kdump was not running: [WARNING]" fi @@ -1096,8 +1078,8 @@ reload() stop_fadump() { - echo 0 > $FADUMP_REGISTER_SYS_NODE - if check_current_fadump_status; then + echo 0 > "$FADUMP_REGISTER_SYS_NODE" + if is_kernel_loaded "fadump"; then derror "fadump: failed to unregister" return 1 fi @@ -1126,7 +1108,7 @@ stop_kdump() reload_fadump() { - if echo 1 > $FADUMP_REGISTER_SYS_NODE; then + if echo 1 > "$FADUMP_REGISTER_SYS_NODE"; then dinfo "fadump: re-registered successfully" return 0 else @@ -1739,7 +1721,7 @@ main() ;; status) EXIT_CODE=0 - check_current_status + is_kernel_loaded "$DEFAULT_DUMP_MODE" case "$?" in 0) dinfo "Kdump is operational" From 383cb622029a52dd1cb460144aa8e62ed0907d73 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:03 +0100 Subject: [PATCH 317/454] mkfadumprd: drop unset globals from debug output mkfadumprd doesn't call prepare_kdump_bootinfo from kdump-lib.sh. Thus both KDUMP_KERNELVER and DEFAULT_INITRD are always empty. Simply remove them from the debug print. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- mkfadumprd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 mkfadumprd diff --git a/mkfadumprd b/mkfadumprd old mode 100644 new mode 100755 index 2fc396c..719e150 --- a/mkfadumprd +++ b/mkfadumprd @@ -37,7 +37,7 @@ FADUMP_INITRD="$MKFADUMPRD_TMPDIR/fadump.img" ### First build an initramfs with dump capture capability # this file tells the initrd is fadump enabled touch "$MKFADUMPRD_TMPDIR/fadump.initramfs" -ddebug "rebuild fadump initrd: $FADUMP_INITRD $DEFAULT_INITRD $KDUMP_KERNELVER" +ddebug "rebuild fadump initrd: $FADUMP_INITRD" # Don't use squash for capture image or default image as it negatively impacts # compression ratio and increases the size of the initramfs image. # Don't compress the capture image as uncompressed image is needed immediately. From 88919b73f01ed630843893b0fcf4fec57b91ac22 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:04 +0100 Subject: [PATCH 318/454] kdump-lib: always specify version in is_squash_available is_squash_available is only used in dracut-module-setup.sh and mkdumprd. Neither of the two scripts calls prepare_kdump_bootinfo which determines and sets KDUMP_KERNELVER. Thus KDUMP_KERNELVER is only non-zero if it explicitly specified by the user in /etc/sysconfig/kdump (and the file gets sourced, which is not the case for drachu-module-setup.sh). In theory this can even lead to bugs. For example consider the case when a debug kernel is running. In that case kdumpctl will try to use the non-debug version of the kernel while is_squash_available will make its decision based on the debug version. So in case the debug kernel has squash available but the non-debug kernel doesn't mkdumprd will try to add it nevertheless. Thus factor out the kernel version detection from prepare_kdump_bootinfo and make use of the new function when checking for the availability of those kernel modules. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdump-lib.sh | 64 +++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index c3091c8..0109b95 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -24,12 +24,11 @@ is_fadump_capable() is_squash_available() { + local _version kmodule + + _version=$(_get_kdump_kernel_version) for kmodule in squashfs overlay loop; do - if [[ -z $KDUMP_KERNELVER ]]; then - modprobe --dry-run $kmodule &> /dev/null || return 1 - else - modprobe -S "$KDUMP_KERNELVER" --dry-run $kmodule &> /dev/null || return 1 - fi + modprobe -S "$_version" --dry-run $kmodule &> /dev/null || return 1 done } @@ -687,6 +686,31 @@ prepare_kdump_kernel() echo "$kdump_kernel" } +_get_kdump_kernel_version() +{ + local _version _version_nondebug + + if [[ -n "$KDUMP_KERNELVER" ]]; then + echo "$KDUMP_KERNELVER" + return + fi + + _version=$(uname -r) + if [[ ! "$_version" =~ \+debug$ ]]; then + echo "$_version" + return + fi + + _version_nondebug=${_version%+debug} + if [[ -f "$(prepare_kdump_kernel "$_version_nondebug")" ]]; then + dinfo "Use of debug kernel detected. Trying to use $_version_nondebug" + echo "$_version_nondebug" + else + dinfo "Use of debug kernel detected but cannot find $_version_nondebug. Falling back to $_version" + echo "$_version" + fi +} + # # Detect initrd and kernel location, results are stored in global environmental variables: # KDUMP_BOOTDIR, KDUMP_KERNELVER, KDUMP_KERNEL, DEFAULT_INITRD, and KDUMP_INITRD @@ -696,37 +720,11 @@ prepare_kdump_kernel() # prepare_kdump_bootinfo() { - local boot_initrdlist nondebug_kernelver debug_kernelver - local default_initrd_base var_target_initrd_dir - - if [[ -z $KDUMP_KERNELVER ]]; then - KDUMP_KERNELVER=$(uname -r) - - # Fadump uses the regular bootloader, unlike kdump. So, use the same version - # for default kernel and capture kernel unless specified explicitly with - # KDUMP_KERNELVER option. - if ! is_fadump_capable; then - nondebug_kernelver=$(sed -n -e 's/\(.*\)+debug$/\1/p' <<< "$KDUMP_KERNELVER") - fi - fi - - # Use nondebug kernel if possible, because debug kernel will consume more memory and may oom. - if [[ -n $nondebug_kernelver ]]; then - dinfo "Trying to use $nondebug_kernelver." - debug_kernelver=$KDUMP_KERNELVER - KDUMP_KERNELVER=$nondebug_kernelver - fi + local boot_initrdlist default_initrd_base var_target_initrd_dir + KDUMP_KERNELVER=$(_get_kdump_kernel_version) KDUMP_KERNEL=$(prepare_kdump_kernel "$KDUMP_KERNELVER") - if ! [[ -e $KDUMP_KERNEL ]]; then - if [[ -n $debug_kernelver ]]; then - dinfo "Fallback to using debug kernel" - KDUMP_KERNELVER=$debug_kernelver - KDUMP_KERNEL=$(prepare_kdump_kernel "$KDUMP_KERNELVER") - fi - fi - if ! [[ -e $KDUMP_KERNEL ]]; then derror "Failed to detect kdump kernel location" return 1 From 269c26972d52cda24e2a1b6653a1a964b313cc6a Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:05 +0100 Subject: [PATCH 319/454] unit tests: add tests for prepare_cmdline prepare_cmdline is totally broken. For example if the remove list ($2) is empty it removes all white spaces or if a parameter has a quoted value containing a white space it only removes the first part of the parameter up to the first space. Thus add a test case that shows what the function should do in order to fix it in subsequent patches. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- spec/kdump-lib_spec.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/kdump-lib_spec.sh b/spec/kdump-lib_spec.sh index 8c91480..3d10006 100644 --- a/spec/kdump-lib_spec.sh +++ b/spec/kdump-lib_spec.sh @@ -48,4 +48,36 @@ Describe 'kdump-lib' End End + Describe 'prepare_cmdline()' + get_bootcpu_apicid() { + echo 1 + } + + get_watchdog_drvs() { + echo foo + } + + add="disable_cpu_apicid=1 foo.pretimeout=0" + + Parameters + #test cmdline remove add result + "#1" "a b c" "" "" "a b c" + "#2" "a b c" "b" "" "a c" + "#3" "a b=x c" "b" "" "a c" + "#4" "a b='x y' c" "b" "" "a c" + "#5" "a b='x y' c" "b=x" "" "a c" + "#6" "a b='x y' c" "b='x y'" "" "a c" + "#7" "a b c" "" "x" "a b c x" + "#8" "a b c" "" "x=1" "a b c x=1" + "#9" "a b c" "" "x='1 2'" "a b c x='1 2'" + "#10" "a b c" "a" "x='1 2'" "b c x='1 2'" + "#11" "a b c" "x" "x='1 2'" "a b c x='1 2'" + End + + It "Test $1: should generate the correct kernel command line" + When call prepare_cmdline "$2" "$3" "$4" + The output should equal "$5 $add" + End + End + End From d55a0565585aa22db069cf5f5fa1955373be60b3 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:06 +0100 Subject: [PATCH 320/454] kdumpctl: move aws workaround to kdump-lib Move the workaround for aws graviton cpus from load_kdump to prepare_cmdline. This (1) makes the workaround available also for other callers of prepare_cmdline (although not needed at the moment) and (2) makes it easier to fix the problems found by the unit test included earlier as all changes to the cmdline are done at one place now. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdump-lib.sh | 9 +++++++++ kdumpctl | 17 ----------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 0109b95..bea74b2 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -22,6 +22,11 @@ is_fadump_capable() return 1 } +is_aws_aarch64() +{ + [[ "$(lscpu | grep "BIOS Model name")" =~ "AWS Graviton" ]] +} + is_squash_available() { local _version kmodule @@ -846,6 +851,10 @@ prepare_cmdline() fi done + # This is a workaround on AWS platform. Always remove irqpoll since it + # may cause the hot-remove of some pci hotplug device. + is_aws_aarch64 && cmdline=$(remove_cmdline_param "${cmdline}" irqpoll) + echo "$cmdline" } diff --git a/kdumpctl b/kdumpctl index dd4bae6..ce3f23f 100755 --- a/kdumpctl +++ b/kdumpctl @@ -656,18 +656,6 @@ function remove_kdump_kernel_key() keyctl unlink "$KDUMP_KEY_ID" %:.ima } -function is_aws_aarch64() -{ - local _bios_model - - _bios_model=$(lscpu | grep "BIOS Model name") - if [[ "${_bios_model}" =~ "AWS Graviton" ]]; then - return 0 - fi - - return 1 -} - # Load the kdump kernel specified in /etc/sysconfig/kdump # If none is specified, try to load a kdump kernel with the same version # as the currently running kernel. @@ -677,11 +665,6 @@ load_kdump() KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") KDUMP_COMMANDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}") - # This is a workaround on AWS platform, since irqpoll may cause the hot-remove of some pci hotplug device - if is_aws_aarch64; then - KDUMP_COMMANDLINE=$(remove_cmdline_param "${KDUMP_COMMANDLINE}" irqpoll) - fi - # For secureboot enabled machines, use new kexec file based syscall. # Old syscall will always fail as it does not have capability to # to kernel signature verification. From 0f6ad91be85d5aec983a00ca54adb1b130889bc2 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:07 +0100 Subject: [PATCH 321/454] kdump-lib: fix prepare_cmdline A recently added unit test found that prepare_cmdline has several problems. For example an empty remove list will remove all spaces or when the cmdline contains a parameter with quoted values containing spaces will only remove the beginning up to the first space. Furthermore the old design requires lots of subshells and pipes. This patch rewrites prepare_cmdline in a way that makes the unit test happy and tries to use as many bash built-ins as possible. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdump-lib.sh | 126 ++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 61 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index bea74b2..6b0a83d 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -526,24 +526,6 @@ is_kernel_loaded() [[ $(< $_sysfs) -eq 1 ]] } -# remove_cmdline_param [] ... [] -# Remove a list of kernel parameters from a given kernel cmdline and print the result. -# For each "arg" in the removing params list, "arg" and "arg=xxx" will be removed if exists. -remove_cmdline_param() -{ - local cmdline=$1 - shift - - for arg in "$@"; do - cmdline=$(echo "$cmdline" | - sed -e "s/\b$arg=[^ ]*//g" \ - -e "s/^$arg\b//g" \ - -e "s/[[:space:]]$arg\b//g" \ - -e "s/\s\+/ /g") - done - echo "$cmdline" -} - # # This function returns the "apicid" of the boot # cpu (cpu 0) if present. @@ -558,23 +540,6 @@ get_bootcpu_apicid() /proc/cpuinfo } -# -# append_cmdline -# This function appends argument "$2=$3" to string ($1) if not already present. -# -append_cmdline() -{ - local cmdline=$1 - local newstr=${cmdline/$2/""} - - # unchanged str implies argument wasn't there - if [[ $cmdline == "$newstr" ]]; then - cmdline="${cmdline} ${2}=${3}" - fi - - echo "$cmdline" -} - # This function check iomem and determines if we have more than # 4GB of ram available. Returns 1 if we do, 0 if we dont need_64bit_headers() @@ -792,26 +757,46 @@ get_watchdog_drvs() echo "$_wdtdrvs" } +_cmdline_parse() +{ + local opt val + + while read -r opt; do + if [[ $opt =~ = ]]; then + val=${opt#*=} + opt=${opt%%=*} + # ignore options like 'foo=' + [[ -z $val ]] && continue + # xargs removes quotes, add them again + [[ $val =~ [[:space:]] ]] && val="\"$val\"" + else + val="" + fi + + echo "$opt $val" + done <<< "$(echo "$1" | xargs -n 1 echo)" +} + # # prepare_cmdline # This function performs a series of edits on the command line. # Store the final result in global $KDUMP_COMMANDLINE. prepare_cmdline() { - local cmdline id arg + local in out append opt val id drv + local -A remove + + in=${1:-$(< /proc/cmdline)} + while read -r opt val; do + [[ -n "$opt" ]] || continue + remove[$opt]=1 + done <<< "$(_cmdline_parse "$2")" + append=$3 - if [[ -z $1 ]]; then - cmdline=$(< /proc/cmdline) - else - cmdline="$1" - fi # These params should always be removed - cmdline=$(remove_cmdline_param "$cmdline" crashkernel panic_on_warn) - # These params can be removed configurably - while read -r arg; do - cmdline=$(remove_cmdline_param "$cmdline" "$arg") - done <<< "$(echo "$2" | xargs -n 1 echo)" + remove[crashkernel]=1 + remove[panic_on_warn]=1 # Always remove "root=X", as we now explicitly generate all kinds # of dump target mount information including root fs. @@ -819,43 +804,62 @@ prepare_cmdline() # We do this before KDUMP_COMMANDLINE_APPEND, if one really cares # about it(e.g. for debug purpose), then can pass "root=X" using # KDUMP_COMMANDLINE_APPEND. - cmdline=$(remove_cmdline_param "$cmdline" root) + remove[root]=1 # With the help of "--hostonly-cmdline", we can avoid some interitage. - cmdline=$(remove_cmdline_param "$cmdline" rd.lvm.lv rd.luks.uuid rd.dm.uuid rd.md.uuid fcoe) + remove[rd.lvm.lv]=1 + remove[rd.luks.uuid]=1 + remove[rd.dm.uuid]=1 + remove[rd.md.uuid]=1 + remove[fcoe]=1 # Remove netroot, rd.iscsi.initiator and iscsi_initiator since # we get duplicate entries for the same in case iscsi code adds # it as well. - cmdline=$(remove_cmdline_param "$cmdline" netroot rd.iscsi.initiator iscsi_initiator) + remove[netroot]=1 + remove[rd.iscsi.initiator]=1 + remove[iscsi_initiator]=1 - cmdline="${cmdline} $3" + while read -r opt val; do + [[ -n "$opt" ]] || continue + [[ -n "${remove[$opt]}" ]] && continue + + if [[ -n "$val" ]]; then + out+="$opt=$val " + else + out+="$opt " + fi + done <<< "$(_cmdline_parse "$in")" + + out+="$append " id=$(get_bootcpu_apicid) - if [[ -n ${id} ]]; then - cmdline=$(append_cmdline "$cmdline" disable_cpu_apicid "$id") + if [[ -n "${id}" ]]; then + out+="disable_cpu_apicid=$id " fi # If any watchdog is used, set it's pretimeout to 0. pretimeout let # watchdog panic the kernel first, and reset the system after the # panic. If the system is already in kdump, panic is not helpful # and only increase the chance of watchdog failure. - for i in $(get_watchdog_drvs); do - cmdline+=" $i.pretimeout=0" + for drv in $(get_watchdog_drvs); do + out+="$drv.pretimeout=0 " - if [[ $i == hpwdt ]]; then - # hpwdt have a special parameter kdumptimeout, is's only suppose - # to be set to non-zero in first kernel. In kdump, non-zero - # value could prevent the watchdog from resetting the system. - cmdline+=" $i.kdumptimeout=0" + if [[ $drv == hpwdt ]]; then + # hpwdt have a special parameter kdumptimeout, it is + # only supposed to be set to non-zero in first kernel. + # In kdump, non-zero value could prevent the watchdog + # from resetting the system. + out+="$drv.kdumptimeout=0 " fi done # This is a workaround on AWS platform. Always remove irqpoll since it # may cause the hot-remove of some pci hotplug device. - is_aws_aarch64 && cmdline=$(remove_cmdline_param "${cmdline}" irqpoll) + is_aws_aarch64 && out=$(echo "$out" | sed -e "/\//") - echo "$cmdline" + # Trim unnecessary whitespaces + echo "$out" | sed -e "s/^ *//g" -e "s/ *$//g" -e "s/ \+/ /g" } PROC_IOMEM=/proc/iomem From 33b307af20c7cd82b4de8bf44dbb3977391b7edd Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:08 +0100 Subject: [PATCH 322/454] kdumpctl: cleanup 'start' The function has many block of the kind if ! cmd; then derror "Starting kdump: [FAILED]" return 1 fi This duplicates code and makes the function hard to read. Thus move the block to the calling function. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/kdumpctl b/kdumpctl index ce3f23f..0dae9b7 100755 --- a/kdumpctl +++ b/kdumpctl @@ -986,46 +986,26 @@ check_final_action_config() start() { - if ! check_dump_feasibility; then - derror "Starting kdump: [FAILED]" - return 1 - fi - - if ! parse_config; then - derror "Starting kdump: [FAILED]" - return 1 - fi + check_dump_feasibility || return + parse_config || return if sestatus 2> /dev/null | grep -q "SELinux status.*enabled"; then selinux_relabel fi - if ! save_raw; then - derror "Starting kdump: [FAILED]" - return 1 - fi + save_raw || return if [[ $DEFAULT_DUMP_MODE == "kdump" ]] && is_kernel_loaded "kdump"; then dwarn "Kdump already running: [WARNING]" return 0 fi - if ! check_and_wait_network_ready; then - derror "Starting kdump: [FAILED]" - return 1 - fi - - if ! check_rebuild; then - derror "Starting kdump: [FAILED]" - return 1 - fi - - if ! start_dump; then - derror "Starting kdump: [FAILED]" - return 1 - fi + check_and_wait_network_ready || return + check_rebuild || return + start_dump || return dinfo "Starting kdump: [OK]" + return 0 } reload() @@ -1697,7 +1677,10 @@ main() case "$1" in start) - start + if ! start; then + derror "Starting kdump: [FAILED]" + exit 1 + fi ;; stop) stop @@ -1722,7 +1705,10 @@ main() ;; restart) stop - start + if ! start; then + derror "Starting kdump: [FAILED]" + exit 1 + fi ;; rebuild) rebuild From 5eefcf2e9434108493b04ddefac6a26909071241 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:09 +0100 Subject: [PATCH 323/454] kdumpctl: cleanup 'stop' Like for 'start' move the printing of the error message to the calling function. This not only makes the code more consistent to 'start' but also prevents 'kdumpctl restart' to call 'start' in case 'stop' has failed. This doesn't impact the case when 'kdumpctl restart' is run without any crash kernel being loaded as kexec will still return success in that case. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kdumpctl b/kdumpctl index 0dae9b7..1534fa5 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1090,15 +1090,9 @@ reload_fadump() stop() { if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then - stop_fadump + stop_fadump || return else - stop_kdump - fi - - # shellcheck disable=SC2181 - if [[ $? != 0 ]]; then - derror "Stopping kdump: [FAILED]" - return 1 + stop_kdump || return fi dinfo "Stopping kdump: [OK]" @@ -1683,7 +1677,10 @@ main() fi ;; stop) - stop + if ! stop; then + derror "Stopping kdump: [FAILED]" + exit 1 + fi ;; status) EXIT_CODE=0 @@ -1704,7 +1701,10 @@ main() reload ;; restart) - stop + if ! stop; then + derror "Stopping kdump: [FAILED]" + exit 1 + fi if ! start; then derror "Starting kdump: [FAILED]" exit 1 From 37577b93ed3519414233be95974917d5c451f5dd Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:10 +0100 Subject: [PATCH 324/454] kdumpctl: refractor check_rebuild check_rebuild uses a bunch of local variables to store the result of the different checks performed. At the end of the function it then evaluates which check failed to print an appropriate info and trigger a rebuild if needed. This not only makes the function hard to read but also requires all checks to be executed even if an earlier one already determined that the initrd needs to be rebuild. Thus refractor check_rebuild such that it only checks whether the initrd needs to rebuild and trigger the rebuild by the caller (if needed). While at it rename the function to need_initrd_rebuild. Furthermore also move setup_initrd to the caller so it is more consisted with the other users of the function. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 83 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/kdumpctl b/kdumpctl index 1534fa5..1952a10 100755 --- a/kdumpctl +++ b/kdumpctl @@ -560,72 +560,58 @@ check_system_modified() return 0 } -check_rebuild() +# need_initrd_rebuild - check whether the initrd needs to be rebuild +# Returns: +# 0 if does not need to be rebuild +# 1 if it needs to be rebuild +# 2 if an error occurred +need_initrd_rebuild() { - local capture_capable_initrd="1" local force_rebuild force_no_rebuild - local ret system_modified="0" - setup_initrd || return 1 - - force_no_rebuild=${OPT[force_no_rebuild]} - force_no_rebuild=${force_no_rebuild:-0} + force_no_rebuild=${OPT[force_no_rebuild]:-0} if [[ $force_no_rebuild != "0" ]] && [[ $force_no_rebuild != "1" ]]; then derror "Error: force_no_rebuild value is invalid" - return 1 + return 2 fi - force_rebuild=${OPT[force_rebuild]} - force_rebuild=${force_rebuild:-0} + force_rebuild=${OPT[force_rebuild]:-0} if [[ $force_rebuild != "0" ]] && [[ $force_rebuild != "1" ]]; then derror "Error: force_rebuild value is invalid" - return 1 + return 2 fi if [[ $force_no_rebuild == "1" && $force_rebuild == "1" ]]; then derror "Error: force_rebuild and force_no_rebuild are enabled simultaneously in kdump.conf" - return 1 + return 2 fi - # Will not rebuild kdump initrd if [[ $force_no_rebuild == "1" ]]; then return 0 fi - #check to see if dependent files has been modified - #since last build of the image file - if [[ -f $TARGET_INITRD ]]; then - image_time=$(stat -c "%Y" "$TARGET_INITRD" 2> /dev/null) + if [[ $force_rebuild == "1" ]]; then + dinfo "Force rebuild $TARGET_INITRD" + return 1 + fi - #in case of fadump mode, check whether the default/target - #initrd is already built with dump capture capability - if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then - capture_capable_initrd=$(lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -c -e ^kdumpbase$ -e ^zz-fadumpinit$) + if [[ ! -f $TARGET_INITRD ]]; then + dinfo "No kdump initial ramdisk found." + return 1 + fi + + # in case of fadump mode, check whether the default/target initrd is + # already built with dump capture capability + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then + if ! lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -q -e ^kdumpbase$ -e ^zz-fadumpinit$; then + dinfo "Rebuild $TARGET_INITRD with dump capture support" + return 1 fi fi + image_time=$(stat -c "%Y" "$TARGET_INITRD" 2> /dev/null) check_system_modified - ret=$? - if [[ $ret -eq 2 ]]; then - return 1 - elif [[ $ret -eq 1 ]]; then - system_modified="1" - fi - if [[ $image_time -eq 0 ]]; then - dinfo "No kdump initial ramdisk found." - elif [[ $capture_capable_initrd == "0" ]]; then - dinfo "Rebuild $TARGET_INITRD with dump capture support" - elif [[ $force_rebuild != "0" ]]; then - dinfo "Force rebuild $TARGET_INITRD" - elif [[ $system_modified != "0" ]]; then - : - else - return 0 - fi - - dinfo "Rebuilding $TARGET_INITRD" - rebuild_initrd } # On ppc64le LPARs, the keys trusted by firmware do not end up in @@ -1001,7 +987,20 @@ start() fi check_and_wait_network_ready || return - check_rebuild || return + setup_initrd || return + need_initrd_rebuild + case "$?" in + 0) + # Nothing to do + ;; + 1) + dinfo "Rebuilding $TARGET_INITRD" + rebuild_initrd || return + ;; + *) + return + ;; + esac start_dump || return dinfo "Starting kdump: [OK]" From d4e877214c9e6b370d4ee67d26386cfb0c9a7cf5 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 12 Jan 2023 16:31:11 +0100 Subject: [PATCH 325/454] kdumpctl: make do_estimate more robust At the beginning of do_estimate it currently checks whether the TARGET_INITRD exists and if not fails with an error message. This not only requires the user to manually trigger the build of the initrd but also ignores all cases where the TARGET_INITRD exists but need to be rebuild. For example when there were changes to kdump.conf or when the system switches from kdump to fadump. All these changes will impact the outcome of do_estimate. Thus properly check whether the initrd needs to be rebuild and if it does trigger the rebuild automatically. To do so move the check whether the TARGET_INITRD has fadump enabled to is_system_modified and call this function. With this force_(no_)rebuild options in kdump.conf are ignored to avoid unnecessary rebuilds. While at it cleanup check_system_modified and rename it to is_system_modified. Furthermore move printing the info that the initrd gets rebuild to rebuild_initrd to avoid every caller has the same line. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 71 ++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/kdumpctl b/kdumpctl index 1952a10..553c392 100755 --- a/kdumpctl +++ b/kdumpctl @@ -16,7 +16,6 @@ KDUMP_INITRD="" TARGET_INITRD="" #kdump shall be the default dump mode DEFAULT_DUMP_MODE="kdump" -image_time=0 standard_kexec_args="-d -p" @@ -117,6 +116,8 @@ rebuild_kdump_initrd() rebuild_initrd() { + dinfo "Rebuilding $TARGET_INITRD" + if [[ ! -w $(dirname "$TARGET_INITRD") ]]; then derror "$(dirname "$TARGET_INITRD") does not have write permission. Cannot rebuild $TARGET_INITRD" return 1 @@ -294,10 +295,12 @@ get_pcs_cluster_modified_files() { local time_stamp local modified_files + local image_time is_generic_fence_kdump && return 1 is_pcs_fence_kdump || return 1 + image_time=$1 time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date) if [[ -n $time_stamp ]] && [[ $time_stamp -gt $image_time ]]; then @@ -341,10 +344,14 @@ setup_initrd() check_files_modified() { + local modified_files="" + local image_time + + image_time=$(stat -c "%Y" "$TARGET_INITRD" 2> /dev/null) #also rebuild when Pacemaker cluster conf is changed and fence kdump is enabled. - modified_files=$(get_pcs_cluster_modified_files) + modified_files=$(get_pcs_cluster_modified_files "$image_time") EXTRA_BINS=${OPT[kdump_post]} CHECK_FILES=${OPT[kdump_pre]} @@ -532,32 +539,25 @@ check_fs_modified() # returns 0 if system is not modified # returns 1 if system is modified -# returns 2 if system modification is invalid -check_system_modified() +# returns 2 if an error occurred +is_system_modified() { local ret [[ -f $TARGET_INITRD ]] || return 1 - check_files_modified - ret=$? - if [[ $ret -ne 0 ]]; then - return $ret - fi - - check_fs_modified - ret=$? - if [[ $ret -ne 0 ]]; then - return $ret + # in case of fadump mode, check whether the default/target initrd is + # already built with dump capture capability + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then + if ! lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -q -e ^kdumpbase$ -e ^zz-fadumpinit$; then + dinfo "Rebuild $TARGET_INITRD with dump capture support" + return 1 + fi fi + check_files_modified || return + check_fs_modified || return check_drivers_modified - ret=$? - if [[ $ret -ne 0 ]]; then - return $ret - fi - - return 0 } # need_initrd_rebuild - check whether the initrd needs to be rebuild @@ -600,18 +600,7 @@ need_initrd_rebuild() return 1 fi - # in case of fadump mode, check whether the default/target initrd is - # already built with dump capture capability - if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then - if ! lsinitrd -f $DRACUT_MODULES_FILE "$TARGET_INITRD" | grep -q -e ^kdumpbase$ -e ^zz-fadumpinit$; then - dinfo "Rebuild $TARGET_INITRD with dump capture support" - return 1 - fi - fi - - image_time=$(stat -c "%Y" "$TARGET_INITRD" 2> /dev/null) - check_system_modified - + is_system_modified } # On ppc64le LPARs, the keys trusted by firmware do not end up in @@ -994,7 +983,6 @@ start() # Nothing to do ;; 1) - dinfo "Rebuilding $TARGET_INITRD" rebuild_initrd || return ;; *) @@ -1105,7 +1093,6 @@ rebuild() setup_initrd || return 1 - dinfo "Rebuilding $TARGET_INITRD" rebuild_initrd } @@ -1118,10 +1105,18 @@ do_estimate() local size_mb=$((1024 * 1024)) setup_initrd - if [[ ! -f $TARGET_INITRD ]]; then - derror "kdumpctl estimate: kdump initramfs is not built yet." - exit 1 - fi + is_system_modified + case "$?" in + 0) + # Nothing to do + ;; + 1) + rebuild_initrd || return + ;; + *) + return + ;; + esac kdump_mods="$(lsinitrd "$TARGET_INITRD" -f /usr/lib/dracut/hostonly-kernel-modules.txt | tr '\n' ' ')" baseline=$(kdump_get_arch_recommend_size) From b41cab7099189abacdfa9e198fb54a7526cca2ae Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 30 Jan 2023 16:18:51 +0800 Subject: [PATCH 326/454] Release 2.0.26-3 Signed-off-by: Coiby Xu --- kexec-tools.spec | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index a413139..5c42af6 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 2%{?dist} +Release: 3%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -414,6 +414,22 @@ fi %endif %changelog +* Jan 30 2023 Coiby - 2.0.26-3 +- kdumpctl: make do_estimate more robust +- kdumpctl: refractor check_rebuild +- kdumpctl: cleanup 'stop' +- kdumpctl: cleanup 'start' +- kdump-lib: fix prepare_cmdline +- kdumpctl: move aws workaround to kdump-lib +- unit tests: add tests for prepare_cmdline +- kdump-lib: always specify version in is_squash_available +- mkfadumprd: drop unset globals from debug output +- kdumpctl: merge check_current_{kdump,fadump}_status +- dracut-early-kdump: explicitly use bash +- dracut-early-kdump: fix shellcheck findings +- kdumpctl: simplify check_failure_action_config +- makedumpfile: Fix wrong exclusion of slab pages on Linux 6.2-rc1 + * Thu Jan 19 2023 Fedora Release Engineering - 2.0.26-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild From 12e6cd2b76a10bb6b52c0cc28ad0e8c8f57a319a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 20 Feb 2023 17:33:08 +0800 Subject: [PATCH 327/454] Use the correct command to get architecture `uname -m` was used by mistake. As a result, kexec-tools failed to update crashkernel=auto during in-place upgrade from RHEL8 to RHEL9. `uname -m` should be used to get architecture instead. Fixes: 5951b5e2 ("Don't try to update crashkernel when bootloader is not installed") Signed-off-by: Coiby Xu Reviewed-by: Lichen Liu --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 553c392..2bec428 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1525,7 +1525,7 @@ reset_crashkernel() _is_bootloader_installed() { - if [[ $(uname -r) == s390x ]]; then + if [[ $(uname -m) == s390x ]]; then test -f /etc/zipl.conf else test -f /boot/grub2/grub.cfg From d9dfea12da33747a92fb97235ef068de1a25e05d Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Tue, 7 Mar 2023 14:45:35 +0100 Subject: [PATCH 328/454] sysconfig: add zfcp.allow_lun_scan to KDUMP_COMMANDLINE_REMOVE on s390 Probing unnecessary I/O devices wastes memory and in extreme cases can cause the crashkernel to run OOM. That's why the s390-tools maintain their own module, 95zdev-kdump [1], that disables auto LUN scanning and only configures zfcp devices that can be used as dump target. So remove zfcp.allow_lun_scan from the kernel command line to prevent that we accidentally overwrite the default set by the module. [1] https://github.com/ibm-s390-linux/s390-tools/blob/master/zdev/dracut/95zdev-kdump/module-setup.sh Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- gen-kdump-sysconfig.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen-kdump-sysconfig.sh b/gen-kdump-sysconfig.sh index bc37dee..5a16e92 100755 --- a/gen-kdump-sysconfig.sh +++ b/gen-kdump-sysconfig.sh @@ -97,7 +97,7 @@ ppc64le) s390x) update_param KEXEC_ARGS "-s" update_param KDUMP_COMMANDLINE_REMOVE \ - "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt ignition.firstboot" + "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt ignition.firstboot zfcp.allow_lun_scan" update_param KDUMP_COMMANDLINE_APPEND \ "nr_cpus=1 cgroup_disable=memory numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd vmcp_cma=0 cma=0 hugetlb_cma=0" ;; From 70c7598ef03a1f611b3a00d8f2254fae1da5b0eb Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 23 Dec 2022 16:03:38 +0800 Subject: [PATCH 329/454] Install nfsv4-related drivers when users specify nfs dumping via dracut_args Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2140721 Currently, if users specify dumping to nfsv4 target via dracut_args --mount ":/var/crash /mnt nfs defaults" it fails with the following errors, [ 5.159760] mount[446]: mount.nfs: Protocol not supported [ 5.164502] systemd[1]: mnt.mount: Mount process exited, code=exited, status=32/n/a [ 5.167616] systemd[1]: mnt.mount: Failed with result 'exit-code'. [FAILED] Failed to mount /mnt. This is because nfsv4-releted drivers are not installed to kdump initrd. mkdumprd calls dracut with "--hostonly-mode strict". If nfsv4-related drivers aren't loaded before calling dracut, they won't be installed. When users specify nfs dumping via dracut_args, kexec-tools won't mount the nfs fs beforehand hence nfsv4-related drivers won't be installed. Note dracut only installs the nfs driver i.e. nfsv3 driver for "--mount ... nfs". So also install nfsv4-related drivers when users specify nfs dumping via dracut_args. Since nfs_layout_nfsv41_files depends on nfsv4, the nfsv4 driver will be installed automatically. As for the reason why we support nfs dumping via dracut_args instead of asking user to use the nfs directive, please refer to commit 74c6f464 ("Support special mount information via 'dracut_args'"). Fixes: 4eedcae5 ("dracut-module-setup.sh: don't include multipath-hostonly") Reported-by: rcheerla@redhat.com Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- mkdumprd | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mkdumprd b/mkdumprd index a069f92..a3e5938 100644 --- a/mkdumprd +++ b/mkdumprd @@ -420,6 +420,15 @@ while read -r config_opt config_val; do verify_core_collector "$config_val" ;; dracut_args) + + # When users specify nfs dumping via dracut_args, kexec-tools won't + # mount nfs fs beforehand thus nfsv4-related drivers won't be installed + # because we call dracut with --hostonly-mode strict. So manually install + # nfsv4-related drivers. + if [[ $(get_dracut_args_fstype "$config_val") == nfs* ]]; then + add_dracut_arg "--add-drivers" nfs_layout_nfsv41_files + fi + while read -r dracut_arg; do add_dracut_arg "$dracut_arg" done <<< "$(echo "$config_val" | xargs -n 1 echo)" From d619b6dabe354100e52b3280c3d36ace88217fd4 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Tue, 4 Apr 2023 14:13:14 +0800 Subject: [PATCH 330/454] kdumpctl: lower the log level in reset_crashkernel_for_installed_kernel Although upgrading the kernel with `rpm -Uvh` is not recommended, the kexec-tools plugin prints confusing error logs when a customer upgrades the kernel through it. ``` kdump: kernel 5.14.0-80.el9.x86_64 doesn't exist kdump: Couldn't find current running kernel ``` Not finding the currently running kernel will only make kdump unable to copy the grub entry parameters to the newly installed kernel, so lower the log level. Signed-off-by: Lichen Liu Reviewed-by: Coiby Xu --- kdumpctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 2bec428..7c32468 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1270,7 +1270,7 @@ _find_kernel_path_by_release() _grubby_kernel_str=$(grubby --info ALL | grep "^kernel=.*$_release\"$") _kernel_path=$(_filter_grubby_kernel_str "$_grubby_kernel_str") if [[ -z $_kernel_path ]]; then - derror "kernel $_release doesn't exist" + ddebug "kernel $_release doesn't exist" return 1 fi echo -n "$_kernel_path" @@ -1642,7 +1642,7 @@ reset_crashkernel_for_installed_kernel() fi if ! _running_kernel=$(_get_current_running_kernel_path); then - derror "Couldn't find current running kernel" + ddebug "Couldn't find current running kernel" exit fi From df6f25ff20a660ce8c300eba95e21e2fed6ed99f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 27 Mar 2023 13:17:32 +0800 Subject: [PATCH 331/454] Tell nmcli to not escape colon when getting the path of connection profile Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2151504 When a NetworManager connection profile contains a colon in the name, "nmcli --get-values UUID,FILENAME" by default would escape the colon because a colon is also used for separating the values. In this case, 99kdumpbase fails to get the correct connection profile path, kdumpctl[5439]: cp: cannot stat '/run/NetworkManager/system-connections/static-52\\\:54\\\:01.nmconnection': No such file or directory kdumpctl[5440]: sed: can't read /tmp/1977-DRACUT_KDUMP_NM/ifcfg-static-52-54-01: No such file or directory kdumpctl[5449]: dracut-install: ERROR: installing '/tmp/1977-DRACUT_KDUMP_NM/ifcfg-static-52-54-01' to '/etc/NetworkManager/system-connections/ifcfg-static-52-54-01' As a result, dumping vmcore to a remote nfs would fail. In our case of getting connection profile path, there is no need to escape the colon so pass "-escape no" to nmcli, [root@localhost ~]# nmcli --get-values UUID,FILENAME c show 659e09c1-a6bd-3549-9be4-a07a1a9a8ffd:/etc/NetworkManager/system-connections/aa\:bb.nmconnection [root@localhost ~]# nmcli -escape no --get-values UUID,FILENAME c show 659e09c1-a6bd-3549-9be4-a07a1a9a8ffd:/etc/NetworkManager/system-connections/aa:bb.nmconnection Suggested-by: Beniamino Galvani Reported-by: Martin Pitt Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index a8ac16c..d8c5574 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -315,7 +315,9 @@ clone_and_modify_nmconnection() { # connection profile based on MAC address _match_nmconnection_by_mac "$_uuid" "$_dev" - _cloned_nmconnection_file_path=$(nmcli --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p") + # If a value contain ":", nmcli by default escape it with "\:" because it + # also uses ":" as the delimiter to separate values. In our case, escaping is not needed. + _cloned_nmconnection_file_path=$(nmcli --escape no --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p") _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename "$_nmconnection_file_path") cp "$_cloned_nmconnection_file_path" "$_tmp_nmconnection_file_path" # change uuid back to old value in case it's refered by other connection From 12d9eff9dcd3bcd5890821c8d8a219b94412aca8 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 28 Mar 2023 16:33:34 +0800 Subject: [PATCH 332/454] Show how much time kdump has waited for the network to be ready Relates: https://bugzilla.redhat.com/show_bug.cgi?id=2151504 Currently, when the network isn't ready, kdump would repeatedly print the same info, [ 29.537230] kdump[671]: Bad kdump network destination: 192.123.1.21 [ 30.559418] kdump[679]: Bad kdump network destination: 192.123.1.21 [ 31.580189] kdump[687]: Bad kdump network destination: 192.123.1.21 This is not user-friendly and users may think kdump has got stuck. So also show much time has waited for the network to be ready, [ 29.546258] kdump[673]: Waiting for network to be ready (50s / 10min) ... [ 32.608967] kdump[697]: Waiting for network to be ready (56s / 10min) Note kdump_get_ip_route no longer prints an error message and it's up to the caller to determine the log level and print relevant messages. And kdump_collect_netif_usage aborts when kdump_get_ip_route fails. Reported-by: Martin Pitt Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- dracut-kdump.sh | 2 ++ dracut-module-setup.sh | 7 ++++++- kdump-lib-initramfs.sh | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 4eec70b..1fc2231 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -495,6 +495,8 @@ wait_online_network() if _route=$(kdump_get_ip_route "$1" 2> /dev/null); then printf "%s" "$_route" return + else + dwarn "Waiting for network to be ready (${_loop}s / 10min)" fi done diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index d8c5574..e744ba5 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -540,7 +540,12 @@ kdump_collect_netif_usage() { local _destaddr _srcaddr _route _netdev _destaddr=$(kdump_get_remote_ip "$1") - _route=$(kdump_get_ip_route "$_destaddr") + + if ! _route=$(kdump_get_ip_route "$_destaddr"); then + derror "Bad kdump network destination: $_destaddr" + exit 1 + fi + _srcaddr=$(kdump_get_ip_route_field "$_route" "src") _netdev=$(kdump_get_ip_route_field "$_route" "dev") diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index e45d6de..a625634 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -167,7 +167,6 @@ is_lvm2_thinp_device() kdump_get_ip_route() { if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then - derror "Bad kdump network destination: $1" exit 1 fi echo "$_route" From ca306cd403bf666a6703a59be4a3ce36406f6659 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 3 Apr 2023 16:54:57 +0200 Subject: [PATCH 333/454] kdump-lib-initramfs: harden is_mounted If the device/mountpoint for findmnt is omitted findmnt will list all mounted filesystems. In that case it will always return "true". So explicitly check if an argument was passed to prevent false-positives. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdump-lib-initramfs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index a625634..c6338c6 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -30,7 +30,7 @@ kdump_get_conf_val() is_mounted() { - findmnt -k -n "$1" > /dev/null 2>&1 + [ -n "$1" ] && findmnt -k -n "$1" > /dev/null 2>&1 } # $1: info type From 258d285c63dabb0e29f88cf3d1b36be572b9e7dd Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 3 Apr 2023 16:54:58 +0200 Subject: [PATCH 334/454] kdump-lib-initramfs: remove is_fs_dump_target The function isn't used anywhere. Thus remove it to keep kdump-lib-initramfs small and simple. Signed-off-by: Philipp Rudo Reviewed-by: Lichen Liu Reviewed-by: Coiby Xu --- kdump-lib-initramfs.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index c6338c6..f7b58a2 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -150,11 +150,6 @@ is_nfs_dump_target() return 1 } -is_fs_dump_target() -{ - [ -n "$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|virtiofs")" ] -} - is_lvm2_thinp_device() { _device_path=$1 From f9d8cabfd1f06fce1e26d6420976609b9a499381 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 3 Apr 2023 16:54:59 +0200 Subject: [PATCH 335/454] dracut-module-setup: remove dead source_ifcfg_file With the NetworkManager rewrite this function in no longer used. This also allows to remove a lot of dead code in kdump-lib. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- dracut-module-setup.sh | 13 ------ kdump-lib.sh | 104 ----------------------------------------- 2 files changed, 117 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index e744ba5..ff53d08 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -91,19 +91,6 @@ kdump_is_vlan() { [[ -f /proc/net/vlan/"$1" ]] } -# $1: netdev name -source_ifcfg_file() { - local ifcfg_file - - dwarning "Network Scripts are deprecated. You are encouraged to set up network by NetworkManager." - ifcfg_file=$(get_ifcfg_filename "$1") - if [[ -f ${ifcfg_file} ]]; then - . "${ifcfg_file}" - else - dwarning "The ifcfg file of $1 is not found!" - fi -} - # $1: repeat times # $2: string to be repeated # $3: separator diff --git a/kdump-lib.sh b/kdump-lib.sh index 6b0a83d..bfc650c 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -292,18 +292,6 @@ is_hostname() echo "$1" | grep -q "[a-zA-Z]" } -# Copied from "/etc/sysconfig/network-scripts/network-functions" -get_hwaddr() -{ - if [[ -f "/sys/class/net/$1/address" ]]; then - awk '{ print toupper($0) }' < "/sys/class/net/$1/address" - elif [[ -d "/sys/class/net/$1" ]]; then - LC_ALL="" LANG="" ip -o link show "$1" 2> /dev/null | - awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/, - "\\1", 1)); }' - fi -} - # Get value by a field using "nmcli -g" # Usage: get_nmcli_value_by_field # @@ -339,98 +327,6 @@ get_nmcli_connection_apath_by_ifname() get_nmcli_value_by_field "GENERAL.CON-PATH" device show "$_ifname" } -get_ifcfg_by_device() -{ - grep -E -i -l "^[[:space:]]*DEVICE=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 -} - -get_ifcfg_by_hwaddr() -{ - grep -E -i -l "^[[:space:]]*HWADDR=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 -} - -get_ifcfg_by_uuid() -{ - grep -E -i -l "^[[:space:]]*UUID=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 -} - -get_ifcfg_by_name() -{ - grep -E -i -l "^[[:space:]]*NAME=\"*${1}\"*[[:space:]]*$" \ - /etc/sysconfig/network-scripts/ifcfg-* 2> /dev/null | head -1 -} - -is_nm_running() -{ - [[ "$(LANG=C nmcli -t --fields running general status 2> /dev/null)" == "running" ]] -} - -is_nm_handling() -{ - LANG=C nmcli -t --fields device,state dev status 2> /dev/null | - grep -q "^\(${1}:connected\)\|\(${1}:connecting.*\)$" -} - -# $1: netdev name -get_ifcfg_nmcli() -{ - local nm_uuid nm_name - local ifcfg_file - - # Get the active nmcli config name of $1 - if is_nm_running && is_nm_handling "${1}"; then - # The configuration "uuid" and "name" generated by nm is wrote to - # the ifcfg file as "UUID=" and "NAME=". - nm_uuid=$(LANG=C nmcli -t --fields uuid,device c show --active 2> /dev/null | - grep "${1}" | head -1 | cut -d':' -f1) - nm_name=$(LANG=C nmcli -t --fields name,device c show --active 2> /dev/null | - grep "${1}" | head -1 | cut -d':' -f1) - ifcfg_file=$(get_ifcfg_by_uuid "${nm_uuid}") - [[ -z ${ifcfg_file} ]] && ifcfg_file=$(get_ifcfg_by_name "${nm_name}") - fi - - echo -n "${ifcfg_file}" -} - -# $1: netdev name -get_ifcfg_legacy() -{ - local ifcfg_file hwaddr - - ifcfg_file="/etc/sysconfig/network-scripts/ifcfg-${1}" - [[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return - - ifcfg_file=$(get_ifcfg_by_name "${1}") - [[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return - - hwaddr=$(get_hwaddr "${1}") - if [[ -n $hwaddr ]]; then - ifcfg_file=$(get_ifcfg_by_hwaddr "${hwaddr}") - [[ -f ${ifcfg_file} ]] && echo -n "${ifcfg_file}" && return - fi - - ifcfg_file=$(get_ifcfg_by_device "${1}") - - echo -n "${ifcfg_file}" -} - -# $1: netdev name -# Return the ifcfg file whole name(including the path) of $1 if any. -get_ifcfg_filename() -{ - local ifcfg_file - - ifcfg_file=$(get_ifcfg_nmcli "${1}") - if [[ -z ${ifcfg_file} ]]; then - ifcfg_file=$(get_ifcfg_legacy "${1}") - fi - - echo -n "${ifcfg_file}" -} - # returns 0 when omission of a module is desired in dracut_args # returns 1 otherwise is_dracut_mod_omitted() From 62c41e5343e12d9463de6eb851762f9953d2eb4d Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 3 Apr 2023 16:55:00 +0200 Subject: [PATCH 336/454] kdump-lib: remove get_nmcli_field_by_conpath The function isn't used anywhere. Thus remove it to keep kdump-lib small and simple. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdump-lib.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index bfc650c..06cdc9e 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -307,15 +307,6 @@ get_nmcli_value_by_field() LANG=C nmcli --get-values "$@" } -# Get nmcli field value of an connection apath (a D-Bus active connection path) -# Usage: get_nmcli_field_by_apath -get_nmcli_field_by_conpath() -{ - local _field=$1 _apath=$2 - - get_nmcli_value_by_field "$_field" connection show "$_apath" -} - # Get nmcli connection apath (a D-Bus active connection path ) by ifname # # apath is used for nmcli connection operations, e.g. From 9eb39cda3cee7c9eef2b8d97aedbbf8bf657ed8a Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 3 Apr 2023 16:55:01 +0200 Subject: [PATCH 337/454] kdump-lib: remove get_nmcli_connection_apath_by_ifname The function isn't used anywhere. Thus remove it to keep kdump-lib small and simple. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdump-lib.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 06cdc9e..722616c 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -307,17 +307,6 @@ get_nmcli_value_by_field() LANG=C nmcli --get-values "$@" } -# Get nmcli connection apath (a D-Bus active connection path ) by ifname -# -# apath is used for nmcli connection operations, e.g. -# $ nmcli connection show $apath -get_nmcli_connection_apath_by_ifname() -{ - local _ifname=$1 - - get_nmcli_value_by_field "GENERAL.CON-PATH" device show "$_ifname" -} - # returns 0 when omission of a module is desired in dracut_args # returns 1 otherwise is_dracut_mod_omitted() From f81e6ca8da7288a65d8bdc307058fe615e6b0dd3 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 3 Apr 2023 16:55:03 +0200 Subject: [PATCH 338/454] kdump-lib: move is_dracut_mod_omitted to kdumpctl The function is only used in kdumpctl. Thus move it there to keep kdump-lib small and simple. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdump-lib.sh | 19 ------------------- kdumpctl | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 722616c..75b31b2 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -307,25 +307,6 @@ get_nmcli_value_by_field() LANG=C nmcli --get-values "$@" } -# returns 0 when omission of a module is desired in dracut_args -# returns 1 otherwise -is_dracut_mod_omitted() -{ - local dracut_args dracut_mod=$1 - - set -- $(kdump_get_conf_val dracut_args) - while [ $# -gt 0 ]; do - case $1 in - -o | --omit) - [[ " ${2//[^[:alnum:]]/ } " == *" $dracut_mod "* ]] && return 0 - ;; - esac - shift - done - - return 1 -} - is_wdt_active() { local active diff --git a/kdumpctl b/kdumpctl index 7c32468..330767b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -45,6 +45,25 @@ if ! dlog_init; then exit 1 fi +# returns 0 when omission of a module is desired in dracut_args +# returns 1 otherwise +is_dracut_mod_omitted() +{ + local dracut_args dracut_mod=$1 + + set -- $(kdump_get_conf_val dracut_args) + while [ $# -gt 0 ]; do + case $1 in + -o | --omit) + [[ " ${2//[^[:alnum:]]/ } " == *" $dracut_mod "* ]] && return 0 + ;; + esac + shift + done + + return 1 +} + single_instance_lock() { local rc timeout=5 lockfile From 0ff44ca6e8f8f0f744d9c7a0baa6a99b2c524cda Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 3 Apr 2023 16:55:04 +0200 Subject: [PATCH 339/454] kdumpctl: fix is_dracut_mod_omitted The function is pretty broken right now. To start with the -o/--omit option allows a quoted, space separated list of modules. But using 'set' breaks quotation and thus only considers the first element in the list. Furthermore dracut uses getopt internally. This means that it is also possible to pass the list via --omit=. Fix the function by making use of getopt for parsing the dracut_args. While at it also add a test cases to cover the functions. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 52 ++++++++++++++++++++++++++++------- kexec-tools.spec | 1 + spec/kdumpctl_general_spec.sh | 48 ++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 10 deletions(-) diff --git a/kdumpctl b/kdumpctl index 330767b..2c647d6 100755 --- a/kdumpctl +++ b/kdumpctl @@ -45,23 +45,55 @@ if ! dlog_init; then exit 1 fi -# returns 0 when omission of a module is desired in dracut_args -# returns 1 otherwise -is_dracut_mod_omitted() +_get_dracut_arg() { - local dracut_args dracut_mod=$1 + local shortopt longopt n tmp + local -a _opt _ret - set -- $(kdump_get_conf_val dracut_args) - while [ $# -gt 0 ]; do + shortopt=$1; shift + longopt=$1; shift + n=0 + + if [[ -n $shortopt ]]; then + _opt+=(-o "${shortopt#-}:") + else + # getopt requires the -o/--option to be set. + _opt+=(-o "") + fi + [[ -n $longopt ]] && _opt+=(--long "${longopt#--}:") + + # make sure bash didn't break quoting + eval set -- "$*" + tmp=$( + unset POSIXLY_CORRECT + getopt -q "${_opt[@]}" -- "$@" + ) + eval set -- "$tmp" + while :; do case $1 in - -o | --omit) - [[ " ${2//[^[:alnum:]]/ } " == *" $dracut_mod "* ]] && return 0 - ;; + "$shortopt"|"$longopt") + _ret+=("$2"); shift + n=$((n+1)) + ;; + --|*) + break + ;; esac shift done - return 1 + echo "${_ret[@]}" + return $n +} + +is_dracut_mod_omitted() +{ + local mod omitted + + mod=$1 + omitted=$(_get_dracut_arg -o --omit "${OPT[dracut_args]}") + + [[ " $omitted " == *" $mod "* ]] } single_instance_lock() diff --git a/kexec-tools.spec b/kexec-tools.spec index 5c42af6..d2a8aca 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -65,6 +65,7 @@ Requires: dracut >= 050 Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool +Requires: util-linux Recommends: grubby Recommends: hostname BuildRequires: make diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index 41fbc29..bb5755c 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -107,6 +107,54 @@ Describe 'kdumpctl' End End + Describe "_get_dracut_arg" + dracut_args='-o "foo bar baz" -t 1 --test="a b c" --omit bla' + Parameters + -o --omit 2 "foo bar baz bla" + -e --empty 0 "" + -t "" 1 "1" + "" --test 1 "a b c" + "" "" 0 "" + End + It "should parse the dracut_args correctly" + When call _get_dracut_arg "$1" "$2" "$dracut_args" + The status should equal $3 + The output should equal "$4" + End + End + + Describe "is_dracut_mod_omitted()" + KDUMP_CONFIG_FILE=$(mktemp -t kdump_conf.XXXXXXXXXX) + cleanup() { + rm -f "$kdump_conf" + } + AfterAll 'cleanup' + + Parameters:dynamic + for opt in '-o ' '--omit ' '--omit='; do + for val in \ + 'foo' \ + '"foo"' \ + '"foo bar baz"' \ + '"bar foo baz"' \ + '"bar baz foo"'; do + %data success foo "$opt$val" + %data success foo "-a x $opt$val -i y" + %data failure xyz "$opt$val" + %data failure xyz "-a x $opt$val -i y" + done + done + %data success foo "-o xxx -o foo" + %data failure foo "-a x -i y" + End + It "shall return $1 for module $2 and dracut_args '$3'" + echo "dracut_args $3" > $KDUMP_CONFIG_FILE + parse_config + When call is_dracut_mod_omitted $2 + The status should be $1 + End + End + Describe '_update_kernel_arg_in_grub_etc_default()' GRUB_ETC_DEFAULT=/tmp/default_grub From 81d89c885f2c07d30738f2a942c23f7b81e60cd0 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 5 May 2023 17:14:40 +0200 Subject: [PATCH 340/454] kdumpctl: Move get_kernel_size to kdumpctl The function is only used in do_estimate. Move it to kdumpctl to prevent confusion. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu Reviewed-by: Coiby Xu --- kdump-lib.sh | 72 ---------------------------------------------------- kdumpctl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 75b31b2..3f9b494 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -853,75 +853,3 @@ get_all_kdump_crypt_dev() get_luks_crypt_dev "$(kdump_get_maj_min "$_dev")" done } - -check_vmlinux() -{ - # Use readelf to check if it's a valid ELF - readelf -h "$1" &> /dev/null || return 1 -} - -get_vmlinux_size() -{ - local size=0 _msize - - while read -r _msize; do - size=$((size + _msize)) - done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2> /dev/stderr)" - - echo $size -} - -try_decompress() -{ - # The obscure use of the "tr" filter is to work around older versions of - # "grep" that report the byte offset of the line instead of the pattern. - - # Try to find the header ($1) and decompress from here - for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"); do - if ! type -P "$3" > /dev/null; then - ddebug "Signiature detected but '$3' is missing, skip this decompressor" - break - fi - - pos=${pos%%:*} - tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null - if check_vmlinux "$5"; then - ddebug "Kernel is extracted with '$3'" - return 0 - fi - done - - return 1 -} - -# Borrowed from linux/scripts/extract-vmlinux -get_kernel_size() -{ - # Prepare temp files: - local tmp img=$1 - - tmp=$(mktemp /tmp/vmlinux-XXX) - trap 'rm -f "$tmp"' 0 - - # Try to check if it's a vmlinux already - check_vmlinux "$img" && get_vmlinux_size "$img" && return 0 - - # That didn't work, so retry after decompression. - try_decompress '\037\213\010' xy gunzip "$img" "$tmp" || - try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" || - try_decompress 'BZh' xy bunzip2 "$img" "$tmp" || - try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" || - try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" || - try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" || - try_decompress '(\265/\375' xxx unzstd "$img" "$tmp" - - # Finally check for uncompressed images or objects: - [[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0 - - # Fallback to use iomem - local _size=0 _seg - while read -r _seg; do - _size=$((_size + 0x${_seg#*-} - 0x${_seg%-*})) - done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)" - echo $_size -} diff --git a/kdumpctl b/kdumpctl index 2c647d6..6341709 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1147,6 +1147,78 @@ rebuild() rebuild_initrd } +check_vmlinux() +{ + # Use readelf to check if it's a valid ELF + readelf -h "$1" &> /dev/null || return 1 +} + +get_vmlinux_size() +{ + local size=0 _msize + + while read -r _msize; do + size=$((size + _msize)) + done <<< "$(readelf -l -W "$1" | awk '/^ LOAD/{print $6}' 2> /dev/stderr)" + + echo $size +} + +try_decompress() +{ + # The obscure use of the "tr" filter is to work around older versions of + # "grep" that report the byte offset of the line instead of the pattern. + + # Try to find the header ($1) and decompress from here + for pos in $(tr "$1\n$2" "\n$2=" < "$4" | grep -abo "^$2"); do + if ! type -P "$3" > /dev/null; then + ddebug "Signiature detected but '$3' is missing, skip this decompressor" + break + fi + + pos=${pos%%:*} + tail "-c+$pos" "$img" | $3 > "$5" 2> /dev/null + if check_vmlinux "$5"; then + ddebug "Kernel is extracted with '$3'" + return 0 + fi + done + + return 1 +} + +# Borrowed from linux/scripts/extract-vmlinux +get_kernel_size() +{ + # Prepare temp files: + local tmp img=$1 + + tmp=$(mktemp /tmp/vmlinux-XXX) + trap 'rm -f "$tmp"' 0 + + # Try to check if it's a vmlinux already + check_vmlinux "$img" && get_vmlinux_size "$img" && return 0 + + # That didn't work, so retry after decompression. + try_decompress '\037\213\010' xy gunzip "$img" "$tmp" || + try_decompress '\3757zXZ\000' abcde unxz "$img" "$tmp" || + try_decompress 'BZh' xy bunzip2 "$img" "$tmp" || + try_decompress '\135\0\0\0' xxx unlzma "$img" "$tmp" || + try_decompress '\211\114\132' xy 'lzop -d' "$img" "$tmp" || + try_decompress '\002!L\030' xxx 'lz4 -d' "$img" "$tmp" || + try_decompress '(\265/\375' xxx unzstd "$img" "$tmp" + + # Finally check for uncompressed images or objects: + [[ $? -eq 0 ]] && get_vmlinux_size "$tmp" && return 0 + + # Fallback to use iomem + local _size=0 _seg + while read -r _seg; do + _size=$((_size + 0x${_seg#*-} - 0x${_seg%-*})) + done <<< "$(grep -E "Kernel (code|rodata|data|bss)" /proc/iomem | cut -d ":" -f 1)" + echo $_size +} + do_estimate() { local kdump_mods From ea00b7db43d12a48676f40614c2c5601a6cd34cc Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 5 May 2023 17:14:41 +0200 Subject: [PATCH 341/454] kdumpctl: Move temp file in get_kernel_size to global temp dir Others will need to use a temporary files, too. In order to avoid potential clashes of multiple trap handlers move the local temp file into a global temp dir. While at it make sure that the trap handler returns the correct exit code. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu Reviewed-by: Coiby Xu --- kdump.service | 1 + kdumpctl | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/kdump.service b/kdump.service index 99feed8..15405dc 100644 --- a/kdump.service +++ b/kdump.service @@ -11,6 +11,7 @@ ExecStop=/usr/bin/kdumpctl stop ExecReload=/usr/bin/kdumpctl reload RemainAfterExit=yes StartLimitInterval=0 +PrivateTmp=yes [Install] WantedBy=multi-user.target diff --git a/kdumpctl b/kdumpctl index 6341709..ecbe0d4 100755 --- a/kdumpctl +++ b/kdumpctl @@ -45,6 +45,13 @@ if ! dlog_init; then exit 1 fi +KDUMP_TMPDIR=$(mktemp -d kdump.XXXX) +trap ' + ret=$?; + rm -rf "$KDUMP_TMPDIR" + exit $ret; + ' EXIT + _get_dracut_arg() { local shortopt longopt n tmp @@ -1193,8 +1200,7 @@ get_kernel_size() # Prepare temp files: local tmp img=$1 - tmp=$(mktemp /tmp/vmlinux-XXX) - trap 'rm -f "$tmp"' 0 + tmp="$KDUMP_TMPDIR/vmlinux" # Try to check if it's a vmlinux already check_vmlinux "$img" && get_vmlinux_size "$img" && return 0 From ea7be0608ed719cc1cb134ecf6ef51a4b7e9f104 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Fri, 5 May 2023 17:14:42 +0200 Subject: [PATCH 342/454] kdumpctl: Add basic UKI support A Unified Kernel Image (UKI) is a single EFI PE executable combining an EFI stub, a kernel image, an initrd image, and the kernel command line. They are defined in the Boot Loader Specification [1] as type #2 entries. UKIs have the advantage that all code as well as meta data that is required to boot the system, not only the kernel image, is combined in a single PE file and can be signed for EFI SecureBoot. This extends the coverage of SecureBoot extensively. For RHEL support for UKI were included into kernel-ark with 16c7e3ee836e ("redhat: Add sub-RPM with a EFI unified kernel image for virtual machines"). There are two problems with UKIs from the kdump point of view at the moment. First, they cannot be directly loaded via kexec_file_load and second, the initrd included isn't suitable for kdump. In order to enable kdump on systems with UKIs build the kdump initrd as usual and extract the kernel image before loading the crash kernel. [1] https://uapi-group.org/specifications/specs/boot_loader_specification/ Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu Reviewed-by: Coiby Xu --- kdump-lib.sh | 26 ++++++++++++++++++++++++-- kdumpctl | 12 +++++++++++- kexec-tools.spec | 1 + 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 3f9b494..3f9e423 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -11,6 +11,17 @@ fi FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" +is_uki() +{ + local img + + img="$1" + + [[ -f "$img" ]] || return + [[ "$(file -b --mime-type "$img")" == application/x-dosexec ]] || return + objdump -h -j .linux "$img" &> /dev/null +} + is_fadump_capable() { # Check if firmware-assisted dump is enabled @@ -489,7 +500,9 @@ prepare_kdump_kernel() read -r machine_id < /etc/machine-id boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"} - boot_imglist="$KDUMP_IMG-$kdump_kernelver$KDUMP_IMG_EXT $machine_id/$kdump_kernelver/$KDUMP_IMG" + boot_imglist="$KDUMP_IMG-$kdump_kernelver$KDUMP_IMG_EXT \ + $machine_id/$kdump_kernelver/$KDUMP_IMG \ + EFI/Linux/$machine_id-$kdump_kernelver.efi" # The kernel of OSTree based systems is not in the standard locations. if is_ostree; then @@ -562,7 +575,11 @@ prepare_kdump_bootinfo() fi # Set KDUMP_BOOTDIR to where kernel image is stored - KDUMP_BOOTDIR=$(dirname "$KDUMP_KERNEL") + if is_uki "$KDUMP_KERNEL"; then + KDUMP_BOOTDIR=/boot + else + KDUMP_BOOTDIR=$(dirname "$KDUMP_KERNEL") + fi # Default initrd should just stay aside of kernel image, try to find it in KDUMP_BOOTDIR boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" @@ -715,6 +732,11 @@ prepare_cmdline() # may cause the hot-remove of some pci hotplug device. is_aws_aarch64 && out=$(echo "$out" | sed -e "/\//") + # Always disable gpt-auto-generator as it hangs during boot of the + # crash kernel. Furthermore we know which disk will be used for dumping + # (if at all) and add it explicitly. + is_uki "$KDUMP_KERNEL" && out+="rd.systemd.gpt_auto=no " + # Trim unnecessary whitespaces echo "$out" | sed -e "s/^ *//g" -e "s/ *$//g" -e "s/ \+/ /g" } diff --git a/kdumpctl b/kdumpctl index ecbe0d4..37f3eb9 100755 --- a/kdumpctl +++ b/kdumpctl @@ -694,7 +694,7 @@ function remove_kdump_kernel_key() # as the currently running kernel. load_kdump() { - local ret + local ret uki KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") KDUMP_COMMANDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}") @@ -707,6 +707,16 @@ load_kdump() load_kdump_kernel_key fi + if is_uki "$KDUMP_KERNEL"; then + uki=$KDUMP_KERNEL + KDUMP_KERNEL=$KDUMP_TMPDIR/vmlinuz + objcopy -O binary --only-section .linux "$uki" "$KDUMP_KERNEL" + sync -f "$KDUMP_KERNEL" + # Make sure the temp file has the correct SELinux label. + # Otherwise starting the kdump.service will fail. + chcon -t boot_t "$KDUMP_KERNEL" + fi + ddebug "$KEXEC $KEXEC_ARGS $standard_kexec_args --command-line=$KDUMP_COMMANDLINE --initrd=$TARGET_INITRD $KDUMP_KERNEL" # The '12' represents an intermediate temporary file descriptor diff --git a/kexec-tools.spec b/kexec-tools.spec index d2a8aca..f1f0423 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -66,6 +66,7 @@ Requires: dracut-network >= 050 Requires: dracut-squash >= 050 Requires: ethtool Requires: util-linux +Requires: binutils Recommends: grubby Recommends: hostname BuildRequires: make From c8643af2707e195533425ce12af56b01509e542e Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Fri, 28 Apr 2023 00:04:45 +0800 Subject: [PATCH 343/454] mkdumprd: add --aggressive-strip as default dracut args The new aggressive strip option was added in dracut 058, which tell dracut to build the initramfs stripping more sections of the ELF binaries (basically strip .symtab, .strtab). These section are only useful for debugging runtime failures, but in kdump kernel, neccessary tools for debug any runtime failure are absent, there is no point keeping these sections. Stripping these section can help save some memory with almost no side effect. So let enable --aggressive-strip by default. Comparison of unpacked initramfs before / after enabling aggressive strip: du -hs image image.aggressive-strip 31M image 29M image.aggressive-strip Signed-off-by: Kairui Song Reviewed-by: Philipp Rudo Reviewed-by: Coiby Xu --- kexec-tools.spec | 6 +++--- mkdumprd | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index f1f0423..6fb97ea 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -61,9 +61,9 @@ Requires(post): servicelog Recommends: keyutils %endif Requires(pre): coreutils sed zlib -Requires: dracut >= 050 -Requires: dracut-network >= 050 -Requires: dracut-squash >= 050 +Requires: dracut >= 058 +Requires: dracut-network >= 058 +Requires: dracut-squash >= 058 Requires: ethtool Requires: util-linux Requires: binutils diff --git a/mkdumprd b/mkdumprd index a3e5938..63a37a7 100644 --- a/mkdumprd +++ b/mkdumprd @@ -27,7 +27,7 @@ SAVE_PATH=$(get_save_path) OVERRIDE_RESETTABLE=0 extra_modules="" -dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict --hostonly-nics '' -o "plymouth resume ifcfg earlykdump") +dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict --hostonly-nics '' --aggressive-strip -o "plymouth resume ifcfg earlykdump") MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" [ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." From 8af05dc45a5e0ee979c96deb61accb6679925350 Mon Sep 17 00:00:00 2001 From: Jeremy Linton Date: Mon, 8 May 2023 19:46:38 -0500 Subject: [PATCH 344/454] kdumpctl: Add support for systemd-boot paths The default systemd-boot installed kernels on fedora end up in the form: /boot/efi/36b54597c46383/6.4.0-0.rc0.20230427git6e98b09da931.5.fc39.aarch64/linux Where the kernel version is a directory containing the kernel (linux) and the initrd. Thus _find_kernel_path_by release needs to be a bit less strict and allow some futher characters on the grubby (really bootctl) output. Signed-off-by: Jeremy Linton Reviewed-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 37f3eb9..844fdad 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1406,7 +1406,7 @@ _filter_grubby_kernel_str() _find_kernel_path_by_release() { local _release="$1" _grubby_kernel_str _kernel_path - _grubby_kernel_str=$(grubby --info ALL | grep "^kernel=.*$_release\"$") + _grubby_kernel_str=$(grubby --info ALL | grep -E "^kernel=.*$_release(\/\w+)?\"$") _kernel_path=$(_filter_grubby_kernel_str "$_grubby_kernel_str") if [[ -z $_kernel_path ]]; then ddebug "kernel $_release doesn't exist" From 5e3d629da7eac381c1ecd0b42127e572a19567f2 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 16 May 2023 09:44:56 +0800 Subject: [PATCH 345/454] Release 2.0.26-4 Signed-off-by: Coiby Xu --- kexec-tools.spec | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 6fb97ea..ee06f87 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 3%{?dist} +Release: 4%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -416,7 +416,27 @@ fi %endif %changelog -* Jan 30 2023 Coiby - 2.0.26-3 +* Tue May 16 2023 Coiby - 2.0.26-4 +- kdumpctl: Add support for systemd-boot paths +- mkdumprd: add --aggressive-strip as default dracut args +- kdumpctl: Add basic UKI support +- kdumpctl: Move temp file in get_kernel_size to global temp dir +- kdumpctl: Move get_kernel_size to kdumpctl +- kdumpctl: fix is_dracut_mod_omitted +- kdump-lib: move is_dracut_mod_omitted to kdumpctl +- kdump-lib: remove get_nmcli_connection_apath_by_ifname +- kdump-lib: remove get_nmcli_field_by_conpath +- dracut-module-setup: remove dead source_ifcfg_file +- kdump-lib-initramfs: remove is_fs_dump_target +- kdump-lib-initramfs: harden is_mounted +- Show how much time kdump has waited for the network to be ready +- Tell nmcli to not escape colon when getting the path of connection profile +- kdumpctl: lower the log level in reset_crashkernel_for_installed_kernel +- Install nfsv4-related drivers when users specify nfs dumping via dracut_args +- sysconfig: add zfcp.allow_lun_scan to KDUMP_COMMANDLINE_REMOVE on s390 +- Use the correct command to get architecture + +* Mon Jan 30 2023 Coiby - 2.0.26-3 - kdumpctl: make do_estimate more robust - kdumpctl: refractor check_rebuild - kdumpctl: cleanup 'stop' From 81d3cc344d20cee900396bb02977d1cbe8a11034 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Thu, 20 Apr 2023 11:26:34 +0800 Subject: [PATCH 346/454] kdump-lib: fix the matching pattern for debug-kernel On aarch64, a 64k kernel's name looks like: vmlinuz-5.14.0-300.el9.aarch64+64k and the corresponding debug kernel's name looks like: vmlinuz-5.14.0-300.el9.aarch64+64k-debug, which ends with the suffix -debug instead of +debug. Fix the matching pattern by [+|-]debug Signed-off-by: Pingfan Liu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 3f9e423..c6bf378 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -536,12 +536,13 @@ _get_kdump_kernel_version() fi _version=$(uname -r) - if [[ ! "$_version" =~ \+debug$ ]]; then + if [[ ! "$_version" =~ [+|-]debug$ ]]; then echo "$_version" return fi _version_nondebug=${_version%+debug} + _version_nondebug=${_version_nondebug%-debug} if [[ -f "$(prepare_kdump_kernel "$_version_nondebug")" ]]; then dinfo "Use of debug kernel detected. Trying to use $_version_nondebug" echo "$_version_nondebug" From 443a43e0750d14c8e3290ecf76535d1746bfac6a Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 24 May 2023 12:01:45 +0800 Subject: [PATCH 347/454] mkdumprd: call dracut with --add-device to install the drivers needed by /boot partition automatically for FIPS Currently, kdump doesn't work on many FIPS-enabled systems including Azure, ESXI, Hyper, POWER and etc. When FIPS is enabled, it needs to access /boot//.vmlinuz-xxx.hmac to verify the integrity of the kernel. However, on those systems, /boot fails to be mounted due to a lack of fs and block device drivers and the system just halted after failing to verify the integrity of the kernel. For example, on Hyper-V, sd_mod, sg, scsi_transport_fc, hv_storvsc and hv_vmbus need to be installed in order for /boot to be mounted. mkdumprd calls dracut with the --no-hostonly-default-device. Following the documentation (man dracut), --no-hostonly-default-device Do not generate implicit host devices like root, swap, fstab, etc. Use "--mount" or "--add-device" to explicitly add devices as needed this patch uses "--add-device" to explicitly add the device of /boot. Note there is already an attempt to fix it in dracut's 01fips module i.e. via the commit 83651776 ("fips: ensure fs module for /boot is installed"). Unfortunately it only installs the file system driver e.g. xfs. Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- mkdumprd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mkdumprd b/mkdumprd index 63a37a7..3932a1f 100644 --- a/mkdumprd +++ b/mkdumprd @@ -463,6 +463,10 @@ if ! is_fadump_capable; then is_dump_to_rootfs && add_mount "$(to_dev_name "$(get_root_fs_device)")" add_dracut_arg "--no-hostonly-default-device" + + if fips-mode-setup --is-enabled 2 > /dev/null; then + add_dracut_arg --add-device "$(findmnt -n -o SOURCE --target /boot)" + fi fi dracut "${dracut_args[@]}" "$@" From cdc0253a3cc1ea4522fa5ac89eb109bd96095548 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 21 Apr 2023 19:09:51 +0800 Subject: [PATCH 348/454] Let _update_kernel_cmdline return the correct return code Currently, for non-s390x systems, the return code is 1 even when _update_kernel_cmdline is correctly executed. This makes callers like reset_crashkernel_after_update fail to print a message if a kernel has its crashkernel updated. Fix it by put the code inside if block for s390x. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdumpctl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 844fdad..9c109da 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1445,7 +1445,11 @@ _update_kernel_cmdline() grubby --args="fadump=$_fadump_val" --update-kernel "$_kernel_path" fi fi - [[ -f /etc/zipl.conf ]] && zipl > /dev/null + + # Don't use "[[ CONDITION ]] && COMMAND" which returns 1 under false CONDITION + if [[ -f /etc/zipl.conf ]]; then + zipl > /dev/null + fi } _valid_grubby_kernel_path() From 5b31b099ae9b40a8f832b07e8364d7b08025fdd6 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 26 Apr 2023 04:48:25 +0800 Subject: [PATCH 349/454] Simplify the management of the kernel parameter crashkernel Currently, kexec-tools only updates the crashkernel to a new default value only when both two conditions are met, - auto_reset_crashkernel=yes in kdump.conf - existing kernels or current running kernel should use the old default value. To address seen corner cases, the logic to tell if the second condition is met becomes quite complex. Instead of making the logic more complex to support aarch64-64k, this patch drops the second condition to simplify the management of the crashkernel kernel parameter. Another change brought by this simplification is kexec-tools will also set up the kernel crashkernel parameter for a fresh install (previously it's limited to osbuild). Note 1. This patch also stop trying to update /etc/default/grub because a) it only affects the static file /boot/grub2/grub.cfg b) grubby is recommended to change the kernel command-line parameters for both Fedora [1] and RHEL9 [2][3] c) For the cases of aarch64 and POWER, different kernels could have different default crashkernel value. 2. Starting with Fedora 37, posttrans rpm scriplet distinguish between package install and upgrade. [1] https://fedoraproject.org/wiki/GRUB_2 [2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/managing_monitoring_and_updating_the_kernel/configuring-kernel-command-line-parameters_managing-monitoring-and-updating-the-kernel#changing-kernel-command-line-parameters-for-all-boot-entries_configuring-kernel-command-line-parameters [3] https://access.redhat.com/solutions/1136173 Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump.conf.5 | 5 ++- kdumpctl | 86 ++++++++++-------------------------------------- kexec-tools.spec | 31 +++-------------- 3 files changed, 25 insertions(+), 97 deletions(-) diff --git a/kdump.conf.5 b/kdump.conf.5 index e3e9900..ec28552 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -28,9 +28,8 @@ understand how this configuration file affects the behavior of kdump. .B auto_reset_crashkernel .RS -determine whether to reset kernel crashkernel to new default value -or not when kexec-tools updates the default crashkernel value and -existing kernels using the old default kernel crashkernel value +determine whether to reset kernel crashkernel parameter to the default value +or not when kexec-tools is updated or a new kernel is installed. .B raw .RS diff --git a/kdumpctl b/kdumpctl index 9c109da..57da1af 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1675,72 +1675,37 @@ _is_bootloader_installed() fi } -# update the crashkernel value in GRUB_ETC_DEFAULT if necessary -# -# called by reset_crashkernel_after_update and inherit its array variable -# _crashkernel_vals -update_crashkernel_in_grub_etc_default_after_update() +_update_crashkernel() { - local _crashkernel _fadump_val - local _dump_mode _old_default_crashkernel _new_default_crashkernel + local _kernel _dump_mode _old_default_crashkernel _new_default_crashkernel _fadump_val _msg - if [[ $(uname -m) == s390x ]]; then - return - fi - - _crashkernel=$(_read_kernel_arg_in_grub_etc_default crashkernel) - - if [[ -z $_crashkernel ]]; then - return - fi - - _fadump_val=$(_read_kernel_arg_in_grub_etc_default fadump) - _dump_mode=$(get_dump_mode_by_fadump_val "$_fadump_val") - - _old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]} - _new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]} - - if [[ $_crashkernel == auto ]] || - [[ $_crashkernel == "$_old_default_crashkernel" && - $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then - _update_kernel_arg_in_grub_etc_default crashkernel "$_new_default_crashkernel" + _kernel=$1 + _dump_mode=$(get_dump_mode_by_kernel "$_kernel") + _old_default_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) + _new_default_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_dump_mode") + if [[ $_old_default_crashkernel != "$_new_default_crashkernel" ]]; then + _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then + _msg="For kernel=$_kernel, crashkernel=$_new_default_crashkernel now. Please reboot the system for the change to take effet." + _msg+=" Note if you don't want kexec-tools to manage the crashkernel kernel parameter, please set auto_reset_crashkernel=no in /etc/kdump.conf." + dinfo "$_msg" + fi fi } + # shellcheck disable=SC2154 # false positive when dereferencing an array reset_crashkernel_after_update() { - local _kernel _crashkernel _dump_mode _fadump_val _old_default_crashkernel _new_default_crashkernel - declare -A _crashkernel_vals + local _kernel if ! _is_bootloader_installed; then return fi - _crashkernel_vals[old_kdump]=$(cat /tmp/old_default_crashkernel 2> /dev/null) - _crashkernel_vals[old_fadump]=$(cat /tmp/old_default_crashkernel_fadump 2> /dev/null) - _crashkernel_vals[new_kdump]=$(get_default_crashkernel kdump) - _crashkernel_vals[new_fadump]=$(get_default_crashkernel fadump) - for _kernel in $(_get_all_kernels_from_grubby ALL); do - _crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) - if [[ $_crashkernel == auto ]]; then - reset_crashkernel "--kernel=$_kernel" - elif [[ -n $_crashkernel ]]; then - _dump_mode=$(get_dump_mode_by_kernel "$_kernel") - _old_default_crashkernel=${_crashkernel_vals[old_${_dump_mode}]} - _new_default_crashkernel=${_crashkernel_vals[new_${_dump_mode}]} - if [[ $_crashkernel == "$_old_default_crashkernel" ]] && - [[ $_new_default_crashkernel != "$_old_default_crashkernel" ]]; then - _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) - if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then - echo "For kernel=$_kernel, crashkernel=$_new_default_crashkernel now." - fi - fi - fi + _update_crashkernel "$_kernel" done - - update_crashkernel_in_grub_etc_default_after_update } # read the value of an environ variable from given environ file path @@ -1764,8 +1729,7 @@ _is_osbuild() reset_crashkernel_for_installed_kernel() { - local _installed_kernel _running_kernel _crashkernel _crashkernel_running - local _dump_mode_running _fadump_val_running + local _installed_kernel # During package install, only try to reset crashkernel for osbuild # thus to avoid calling grubby when installing os via anaconda @@ -1784,21 +1748,7 @@ reset_crashkernel_for_installed_kernel() return fi - if ! _running_kernel=$(_get_current_running_kernel_path); then - ddebug "Couldn't find current running kernel" - exit - fi - - _crashkernel=$(get_grub_kernel_boot_parameter "$_installed_kernel" crashkernel) - _crashkernel_running=$(get_grub_kernel_boot_parameter "$_running_kernel" crashkernel) - _dump_mode_running=$(get_dump_mode_by_kernel "$_running_kernel") - _fadump_val_running=$(get_grub_kernel_boot_parameter "$_kernel" fadump) - - if [[ $_crashkernel != "$_crashkernel_running" ]]; then - if _update_kernel_cmdline "$_installed_kernel" "$_crashkernel_running" "$_dump_mode_running" "$_fadump_val_running"; then - echo "kexec-tools has reset $_installed_kernel to use the new default crashkernel value $_crashkernel_running" - fi - fi + _update_crashkernel "$_installed_kernel" } main() diff --git a/kexec-tools.spec b/kexec-tools.spec index ee06f87..64db9e2 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -260,21 +260,6 @@ chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpini mkdir -p $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ -%pre -# Save the old default crashkernel values to /tmp/ when upgrading the package -# so kdumpctl later can tell if it should update the kernel crashkernel -# parameter in the posttrans scriptlet. Note this feauture of auto-updating -# the kernel crashkernel parameter currently doesn't support ostree, so skip it -# for ostree. -if [ ! -f /run/ostree-booted ] && [ $1 == 2 ] && grep -q get-default-crashkernel /usr/bin/kdumpctl; then - kdumpctl get-default-crashkernel kdump > /tmp/old_default_crashkernel 2>/dev/null -%ifarch ppc64 ppc64le - kdumpctl get-default-crashkernel fadump > /tmp/old_default_crashkernel_fadump 2>/dev/null -%endif -fi -# don't block package update -: - %post # Initial installation %systemd_post kdump.service @@ -341,21 +326,15 @@ do done %posttrans -# Try to reset kernel crashkernel value to new default value based on the old -# default value or set up crasherkernel value for osbuild +# Try to reset kernel crashkernel value to new default value or set up +# crasherkernel value for new install # # Note # 1. Skip ostree systems as they are not supported. -# 2. "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade. The -# former case is used to set up crashkernel for osbuild -if [ ! -f /run/ostree-booted ] && [ $1 == 1 ]; then +# 2. For Fedora 36 and RHEL9, "[ $1 == 1 ]" in posttrans scriptlet means both install and upgrade; +# For Fedora > 36, "[ $1 == 1 ]" only means install and "[ $1 == 2 ]" means upgrade +if [ ! -f /run/ostree-booted ] && [ $1 == 1 -o $1 == 2 ]; then kdumpctl _reset-crashkernel-after-update - rm /tmp/old_default_crashkernel 2>/dev/null -%ifarch ppc64 ppc64le - rm /tmp/old_default_crashkernel_fadump 2>/dev/null -%endif - # dnf would complain about the exit code not being 0. To keep it happy, - # always return 0 : fi From 07b99ecab71ae9dcf4dd6114a9a09b7fb8301e12 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 9 May 2023 12:28:37 +0800 Subject: [PATCH 350/454] Add ShellSpec tests for managing the crashkernel kernel parameter Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdumpctl | 3 +- spec/kdumpctl_manage_crashkernel_spec.sh | 107 +++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 spec/kdumpctl_manage_crashkernel_spec.sh diff --git a/kdumpctl b/kdumpctl index 57da1af..5043a7b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1666,12 +1666,13 @@ reset_crashkernel() fi } +GRUB_CFG=/boot/grub2/grub.cfg _is_bootloader_installed() { if [[ $(uname -m) == s390x ]]; then test -f /etc/zipl.conf else - test -f /boot/grub2/grub.cfg + test -f "$GRUB_CFG" fi } diff --git a/spec/kdumpctl_manage_crashkernel_spec.sh b/spec/kdumpctl_manage_crashkernel_spec.sh new file mode 100644 index 0000000..9078347 --- /dev/null +++ b/spec/kdumpctl_manage_crashkernel_spec.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +Describe 'Management of the kernel crashkernel parameter.' + Include ./kdumpctl + kernel1=/boot/vmlinuz-5.15.6-100.fc34.x86_64 + kernel2=/boot/vmlinuz-5.14.14-200.fc34.x86_64 + old_ck=1G-4G:162M,4G-64G:256M,64G-:512M + new_ck=1G-4G:196M,4G-64G:256M,64G-:512M + KDUMP_SPEC_TEST_RUN_DIR=$(mktemp -u /tmp/spec_test.XXXXXXXXXX) + GRUB_CFG="$KDUMP_SPEC_TEST_RUN_DIR/grub.cfg" + + uname() { + if [[ $1 == '-m' ]]; then + echo -n x86_64 + elif [[ $1 == '-r' ]]; then + echo -n $current_kernel + fi + } + + # dinfo is a bit complex for unit tets, simply mock it + dinfo() { + echo "$1" + } + + kdump_get_arch_recommend_crashkernel() { + echo -n "$new_ck" + } + + setup() { + mkdir -p "$KDUMP_SPEC_TEST_RUN_DIR" + cp -r spec/support/boot_load_entries "$KDUMP_SPEC_TEST_RUN_DIR" + cp spec/support/grub_env "$KDUMP_SPEC_TEST_RUN_DIR"/env_temp + touch "$GRUB_CFG" + + grubby --args crashkernel=$old_ck --update-kernel=$kernel1 + grubby --args crashkernel=$new_ck --update-kernel=$kernel2 + grubby --remove-args fadump --update-kernel=ALL + + } + + cleanup() { + rm -rf "$KDUMP_SPEC_TEST_RUN_DIR" + } + + grubby() { + # - --no-etc-grub-update, not update /etc/default/grub + # - --bad-image-okay, don't check the validity of the image + # - --env, specify custom grub2 environment block file to avoid modifying + # the default /boot/grub2/grubenv + # - --bls-directory, specify custom BootLoaderSpec config files to avoid + # modifying the default /boot/loader/entries + @grubby --no-etc-grub-update --grub2 --config-file="$GRUB_CFG" --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" + } + + Describe "When kexec-tools have its default crashkernel updated, " + + Context "if kexec-tools is updated alone, " + BeforeAll 'setup' + AfterAll 'cleanup' + Specify 'reset_crashkernel_after_update should report updated kernels and note that auto_reset_crashkernel=yes' + When call reset_crashkernel_after_update + The output should include "For kernel=$kernel1, crashkernel=$new_ck now." + The output should not include "For kernel=$kernel2, crashkernel=$new_ck now." + # A hint on how to turn off auto update of crashkernel + The output should include "auto_reset_crashkernel=no" + End + + Specify 'kernel1 should have crashkernel updated' + When call grubby --info $kernel1 + The line 3 of output should include crashkernel="$new_ck" + End + + Specify 'kernel2 should also have crashkernel updated' + When call grubby --info $kernel2 + The line 3 of output should include crashkernel="$new_ck" + End + + End + + Context "If kernel package is installed alone, " + BeforeAll 'setup' + AfterAll 'cleanup' + # BeforeAll somehow doesn't work as expected, manually call setup to bypass this issue. + setup + new_kernel_ver=new_kernel + new_kernel=/boot/vmlinuz-$new_kernel_ver + grubby --add-kernel=$new_kernel --initrd=/boot/initramfs-$new_kernel_ver.img --title=$new_kernel_ver + + Specify 'reset_crashkernel_for_installed_kernel should report the new kernel has its crashkernel updated' + When call reset_crashkernel_for_installed_kernel $new_kernel_ver + The output should include "crashkernel=$new_ck" + End + + Specify 'the new kernel should have crashkernel updated' + When call grubby --info $new_kernel + The output should include crashkernel="$new_ck" + End + + Specify 'kernel1 keeps its crashkernel value' + When call grubby --info $kernel1 + The output should include crashkernel="$old_ck" + End + + End + + End +End From 4311534c85f4f5fe2f9d4a78ee28abed429fc572 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 29 May 2023 17:42:49 +0800 Subject: [PATCH 351/454] Release 2.0.26-5 Signed-off-by: Coiby Xu --- kexec-tools.spec | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 64db9e2..d7d2947 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 4%{?dist} +Release: 5%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -395,6 +395,12 @@ fi %endif %changelog +* Mon May 29 2023 Coiby - 2.0.26-5 +- Simplify the management of the kernel parameter crashkernel +- Let _update_kernel_cmdline return the correct return code +- mkdumprd: call dracut with --add-device to install the drivers needed by /boot partition automatically for FIPS +- kdump-lib: fix the matching pattern for debug-kernel + * Tue May 16 2023 Coiby - 2.0.26-4 - kdumpctl: Add support for systemd-boot paths - mkdumprd: add --aggressive-strip as default dracut args From e42a823daec946da013b63460cded5bd0ff53e48 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 1 Jun 2023 16:05:05 +0800 Subject: [PATCH 352/454] mkdumprd: Use the correct syntax to redirect the stderr to null A space was added by mistake and unfortunately fips-mode-setup refuses an extra parameter, # fips-mode-setup --is-enabled 2 > /dev/null # echo $? 2 # fips-mode-setup --is-enabled 2 Check, enable, or disable the system FIPS mode. usage: /usr/bin/fips-mode-setup --enable|--disable [--no-bootcfg] usage: /usr/bin/fips-mode-setup --check usage: /usr/bin/fips-mode-setup --is-enabled So in this case mkdumprd can never detect if FIPS is enabled. Fix this mistake. Fixes: 443a43e0 ("mkdumprd: call dracut with --add-device to install the drivers needed by /boot partition automatically for FIPS") Signed-off-by: Coiby Xu Reviewed-by: Tao Liu --- mkdumprd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdumprd b/mkdumprd index 3932a1f..f93874d 100644 --- a/mkdumprd +++ b/mkdumprd @@ -464,7 +464,7 @@ if ! is_fadump_capable; then add_dracut_arg "--no-hostonly-default-device" - if fips-mode-setup --is-enabled 2 > /dev/null; then + if fips-mode-setup --is-enabled 2> /dev/null; then add_dracut_arg --add-device "$(findmnt -n -o SOURCE --target /boot)" fi fi From 4da1ffe730d61688f9533d2977764775f1fdd41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Ravier?= Date: Fri, 2 Jun 2023 13:04:27 +0200 Subject: [PATCH 353/454] Make binutils a recommend as it's only needed for UKI support UKI are not supported on rpm-ostree based Fedora variants so let's use recommend for binutils for now to let those not include the package until needed. See: https://github.com/coreos/fedora-coreos-tracker/issues/1496 See: https://github.com/ostreedev/ostree/issues/2753 See: https://src.fedoraproject.org/rpms/kexec-tools/c/ea7be0608ed719cc1cb134ecf6ef51a4b7e9f104?branch=rawhide --- kexec-tools.spec | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index d7d2947..8f2bc6e 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 5%{?dist} +Release: 6%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -66,7 +66,8 @@ Requires: dracut-network >= 058 Requires: dracut-squash >= 058 Requires: ethtool Requires: util-linux -Requires: binutils +# Needed for UKI support +Recommends: binutils Recommends: grubby Recommends: hostname BuildRequires: make @@ -395,6 +396,9 @@ fi %endif %changelog +* Fri Jun 02 2023 Timothée Ravier - 2.0.26-6 +- Make binutils a recommend as it's only needed for UKI support + * Mon May 29 2023 Coiby - 2.0.26-5 - Simplify the management of the kernel parameter crashkernel - Let _update_kernel_cmdline return the correct return code From eabbf9d6a07c00b66f49aebe5eaee864707218b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Ravier?= Date: Fri, 2 Jun 2023 13:07:04 +0200 Subject: [PATCH 354/454] Whitespace fixes --- kexec-tools.spec | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 8f2bc6e..e69a258 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -273,8 +273,8 @@ servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match %endif # This portion of the script is temporary. Its only here -# to fix up broken boxes that require special settings -# in /etc/sysconfig/kdump. It will be removed when +# to fix up broken boxes that require special settings +# in /etc/sysconfig/kdump. It will be removed when # These systems are fixed. if [ -d /proc/bus/mckinley ] @@ -287,7 +287,7 @@ then elif [ -d /proc/sgi_sn ] then # This is for SGI SN boxes - # They require the --noio option to kexec + # They require the --noio option to kexec # since they don't support legacy io sed -e's/\(^KEXEC_ARGS.*\)\("$\)/\1 --noio"/' \ /etc/sysconfig/kdump > /etc/sysconfig/kdump.new @@ -1131,7 +1131,7 @@ fi - Revert "dracut-module-setup.sh: pass correct ip= param for ipv6" * Sat Apr 28 2018 Dave Young - 2.0.17-2 -- pull in makedumpfile 1.6.3 +- pull in makedumpfile 1.6.3 * Sat Apr 28 2018 Dave Young - 2.0.17-1 - pull in 2.0.17 @@ -1191,10 +1191,10 @@ fi * Tue Aug 8 2017 Dave Young - 2.0.15-10 - Improve 'cpu add' udev rules - module-setup: suppress the early iscsi error messages -- mkdumprd: use 300s as the default systemd unit timeout for kdump mount +- mkdumprd: use 300s as the default systemd unit timeout for kdump mount * Mon Aug 7 2017 Dave Young - 2.0.15-9 -- fix makedumpfile bug 1474706 +- fix makedumpfile bug 1474706 * Thu Aug 03 2017 Fedora Release Engineering - 2.0.15-8 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild @@ -1350,9 +1350,9 @@ fi - module-setup: Use get_ifcfg_filename() to get the proper ifcfg file * Mon May 30 2016 Dave Young - 2.0.12-4 -- update kdump anaconda addon to add mem range in tui +- update kdump anaconda addon to add mem range in tui - .gitignore: Update to make it more generic -- kdumpctl: check_rebuild improvement +- kdumpctl: check_rebuild improvement - kdumpctl: Do not rebuild initramfs when $KDUMP_BOOTDIR is read only * Tue Mar 29 2016 Dave Young - 2.0.12-3 @@ -1363,7 +1363,7 @@ fi - ppc64le: fix kexec hang due to ppc64 elf abi breakage * Tue Mar 22 2016 Dave Young - 2.0.12-1 -- Rebase kexec-tools to 2.0.12 +- Rebase kexec-tools to 2.0.12 * Thu Feb 04 2016 Fedora Release Engineering - 2.0.11-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild @@ -1376,7 +1376,7 @@ fi - fix bogus date in changelog * Thu Nov 19 2015 Dave Young - 2.0.11-2 -- Rebase to upstream makedumpfile 1.5.9 +- Rebase to upstream makedumpfile 1.5.9 * Mon Nov 9 2015 Dave Young - 2.0.11-1 - Rebase to upstream kexec-tools 2.0.11 @@ -1386,7 +1386,7 @@ fi - Remove duplicate prefix path ${initdir} * Tue Sep 8 2015 Dave Young - 2.0.10-8 -- update kdump addon to fix a kickstart installationi issue +- update kdump addon to fix a kickstart installationi issue * Wed Aug 19 2015 Dave Young - 2.0.10-7 - add man page for kdumpctl @@ -1728,7 +1728,7 @@ fi * Thu Mar 14 2013 Baoquan He - 2.0.3-69 - Support for eppic language as a subpackage - + * Thu Mar 14 2013 Baoquan He - 2.0.3-68 - tune sysconfig to save memory usage - Remove useless codes related to LOGGER in kdumpctl @@ -1855,7 +1855,7 @@ fi - do not add fstab-sys module in dracut cmdline - omit dash module - network dns config fix -- shell exit value fix +- shell exit value fix * Thu Jul 19 2012 Fedora Release Engineering - 2.0.3-52 - Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild @@ -2182,7 +2182,7 @@ fi - Make makedumpfile a dynamic binary * Mon Jul 06 2009 Neil Horman 2.0.0-19 -- Fix build issue +- Fix build issue * Mon Jul 06 2009 Neil Horman 2.0.0-18 - Updated initscript to use mkdumprd2 if manifest is present @@ -2394,7 +2394,7 @@ fi - updating mkdumprd to use new kcp syntax * Wed Aug 23 2006 Neil Horman - 1.101-48 -- Bumping revision number +- Bumping revision number * Tue Aug 22 2006 Jarod Wilson - 1.101-47 - ppc64 no-more-platform fix @@ -2414,7 +2414,7 @@ fi * Tue Aug 15 2006 Neil Horman - 1.101-44 - updated init script to implement status function/scrub err messages - + * Wed Aug 09 2006 Jarod Wilson - 1.101-43 - Misc spec cleanups and macro-ifications @@ -2422,13 +2422,13 @@ fi - Add %%dir /var/crash, so default kdump setup works * Thu Aug 03 2006 Neil Horman - 1.101-41 -- fix another silly makefile error for makedumpfile +- fix another silly makefile error for makedumpfile * Thu Aug 03 2006 Neil Horman - 1.101-40 -- exclude makedumpfile from build on non-x86[_64] arches +- exclude makedumpfile from build on non-x86[_64] arches * Thu Aug 03 2006 Neil Horman - 1.101-39 -- exclude makedumpfile from build on non-x86[_64] arches +- exclude makedumpfile from build on non-x86[_64] arches * Thu Aug 03 2006 Neil Horman - 1.101-38 - updating makedumpfile makefile to use pkg-config on glib-2.0 @@ -2525,7 +2525,7 @@ fi * Wed Nov 16 2005 Thomas Graf - 1.101-5 - Report missing kdump kernel image as warning - + * Thu Nov 3 2005 Jeff Moyer - 1.101-4 - Build for x86_64 as well. Kdump support doesn't work there, but users should be able to use kexec. From 29fe563644f5e190067aefb41f99e7b9835fa87b Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Mon, 5 Jun 2023 17:35:53 +0800 Subject: [PATCH 355/454] kdump.conf: redirect unknown architecture warning to stderr The warning messages should not be included in the generated files. Redirecting the warning for an unknown architecture to stderr. Signed-off-by: Lichen Liu Reviewed-by: Coiby Xu --- gen-kdump-conf.sh | 2 +- gen-kdump-sysconfig.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gen-kdump-conf.sh b/gen-kdump-conf.sh index a9f124f..4abcd39 100755 --- a/gen-kdump-conf.sh +++ b/gen-kdump-conf.sh @@ -224,7 +224,7 @@ s390x) x86_64) ;; *) - echo "Warning: Unknown architecture '$1', using default kdump.conf template." + echo "Warning: Unknown architecture '$1', using default kdump.conf template." >&2 ;; esac diff --git a/gen-kdump-sysconfig.sh b/gen-kdump-sysconfig.sh index 5a16e92..4a28350 100755 --- a/gen-kdump-sysconfig.sh +++ b/gen-kdump-sysconfig.sh @@ -107,7 +107,7 @@ x86_64) "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 cma=0 hugetlb_cma=0" ;; *) - echo "Warning: Unknown architecture '$1', using default sysconfig template." + echo "Warning: Unknown architecture '$1', using default sysconfig template." >&2 ;; esac From 51efbcf83e26a69fb56466a580b50e5d4867509f Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 13 Jun 2023 17:43:20 +0800 Subject: [PATCH 356/454] kdump-lib: Introduce a help function _crashkernel_add() This help function can manipulate the crashkernel cmdline by adding an number for each item. Also a basic test case for _crashkernel_add() is provided in this patch. Credit to Philipp, who contributes the original code. Signed-off-by: Pingfan Liu Reviewed-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 58 ++++++++++++++++++++++++++++++++++++++++++ spec/kdump-lib_spec.sh | 20 +++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index c6bf378..992e8d9 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -786,6 +786,64 @@ get_recommend_size() echo "0M" } +# $1 crashkernel="" +# $2 delta in unit of MB +_crashkernel_add() +{ + local _ck _add _entry _ret + local _range _size _offset + + _ck="$1" + _add="$2" + _ret="" + + if [[ "$_ck" == *@* ]]; then + _offset="@${_ck##*@}" + _ck=${_ck%@*} + elif [[ "$_ck" == *,high ]] || [[ "$_ck" == *,low ]]; then + _offset=",${_ck##*,}" + _ck=${_ck%,*} + else + _offset='' + fi + + while read -d , -r _entry; do + [[ -n "$_entry" ]] || continue + if [[ "$_entry" == *:* ]]; then + _range=${_entry%:*} + _size=${_entry#*:} + else + _range="" + _size=${_entry} + fi + + case "${_size: -1}" in + K) + _size=${_size::-1} + _size="$((_size + (_add * 1024)))K" + ;; + M) + _size=${_size::-1} + _size="$((_size + _add))M" + ;; + G) + _size=${_size::-1} + _size="$((_size * 1024 + _add))M" + ;; + *) + _size="$((_size + (_add * 1024 * 1024)))" + ;; + esac + + [[ -n "$_range" ]] && _ret+="$_range:" + _ret+="$_size," + done <<< "$_ck," + + _ret=${_ret%,} + [[ -n "$_offset" ]] && _ret+=$_offset + echo "$_ret" +} + # get default crashkernel # $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable kdump_get_arch_recommend_crashkernel() diff --git a/spec/kdump-lib_spec.sh b/spec/kdump-lib_spec.sh index 3d10006..81f0f86 100644 --- a/spec/kdump-lib_spec.sh +++ b/spec/kdump-lib_spec.sh @@ -48,6 +48,26 @@ Describe 'kdump-lib' End End + Describe "_crashkernel_add()" + Context "when the input parameter is '1G-4G:256M,4G-64G:320M,64G-:576M'" + delta=100 + Parameters + "1G-4G:256M,4G-64G:320M,64G-:576M" "1G-4G:356M,4G-64G:420M,64G-:676M" + "1G-4G:256M,4G-64G:320M,64G-:576M@4G" "1G-4G:356M,4G-64G:420M,64G-:676M@4G" + "1G-4G:1G,4G-64G:2G,64G-:3G@4G" "1G-4G:1124M,4G-64G:2148M,64G-:3172M@4G" + "1G-4G:10000K,4G-64G:20000K,64G-:40000K@4G" "1G-4G:112400K,4G-64G:122400K,64G-:142400K@4G" + "300M,high" "400M,high" + "300M,low" "400M,low" + "500M@1G" "600M@1G" + End + It "should add delta to the values after ':'" + + When call _crashkernel_add "$1" "$delta" + The output should equal "$2" + End + End + End + Describe 'prepare_cmdline()' get_bootcpu_apicid() { echo 1 From d8b961be37de09289a2ffff8c9c51cca4d153a92 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 13 Jun 2023 17:43:21 +0800 Subject: [PATCH 357/454] kdump-lib: Introduce parse_kver_from_path() to get kernel version from its path name kdump_get_arch_recommend_crashkernel() expects the kernel version info, while _update_kernel() provides the absolute path, which contains the kernel version info. This patch introduce a dedicated function parse_kver_from_path() to extract the kernel info from the path Credit to Philipp, who contributes the original code. Signed-off-by: Pingfan Liu Reviewed-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 992e8d9..4f31b74 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -526,6 +526,49 @@ prepare_kdump_kernel() echo "$kdump_kernel" } +_is_valid_kver() +{ + [[ -f /usr/lib/modules/$1/modules.dep ]] +} + +# This function is introduced since 64k variant may be installed on 4k or vice versa +# $1 the kernel path name. +parse_kver_from_path() +{ + local _img _kver + + [[ -z "$1" ]] && return + + _img=$1 + BLS_ENTRY_TOKEN=$( + _kver=${_img##*/vmlinuz-} + _kver=${_kver%"$KDUMP_IMG_EXT"} + if _is_valid_kver "$_kver"; then + echo "$_kver" + return + fi + + # BLS recommended image names, i.e. $BOOT///linux + _kver=${_img##*/"$BLS_ENTRY_TOKEN"/} + _kver=${_kver%%/*} + if _is_valid_kver "$_kver"; then + echo "$_kver" + return + fi + + # Fedora UKI installation, i.e. $BOOT/efi/EFI/Linux/-.efi + _kver=${_img##*/"$BLS_ENTRY_TOKEN"-} + _kver=${_kver%.efi} + if _is_valid_kver "$_kver"; then + echo "$_kver" + return + fi + + ddebug "Could not parse version from $_img" +} + _get_kdump_kernel_version() { local _version _version_nondebug From 05c48614438611b83033b382de391afd87c6bc5b Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 13 Jun 2023 17:43:22 +0800 Subject: [PATCH 358/454] kdump-lib: add support for 64K aarch64 On aarch64, both 4K and 64K kernel can be installed, while they demand different size reserved memory for kdump kernel. 'get_conf PAGE_SIZE' can not work if installing a 64K kernel when running a 4K kernel. Hence resorting to the kernel release naming rules. At present, the 64K kernel has the keyword '64k' in its suffix. The base line for 64K is decided based on 4K. The diff 100M is picked up since on a high end machine without smmu enabled, the diff of MemFree is 82M. As for the smmu case, a huge difference in the memory consumption lies between 64k and 4k driver. And it should be calculated separatedly. Signed-off-by: Pingfan Liu Reviewed-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 21 ++++++++++++++++++++- kdumpctl | 6 ++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 4f31b74..68431a0 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -889,6 +889,7 @@ _crashkernel_add() # get default crashkernel # $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable +# $2 kernel-release, if not specified, got by _get_kdump_kernel_version kdump_get_arch_recommend_crashkernel() { local _arch _ck_cmdline _dump_mode @@ -908,8 +909,26 @@ kdump_get_arch_recommend_crashkernel() if [[ $_arch == "x86_64" ]] || [[ $_arch == "s390x" ]]; then _ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M" elif [[ $_arch == "aarch64" ]]; then - # For 4KB page size, the formula is based on x86 plus extra = 64M + local _running_kernel + local _delta=0 + + # Base line for 4K variant kernel. The formula is based on x86 plus extra = 64M _ck_cmdline="1G-4G:256M,4G-64G:320M,64G-:576M" + if [[ -z "$2" ]]; then + _running_kernel=$(_get_kdump_kernel_version) + else + _running_kernel=$2 + fi + + # the naming convention of 64k variant suffixes with +64k, e.g. "vmlinuz-5.14.0-312.el9.aarch64+64k" + if echo "$_running_kernel" | grep -q 64k; then + # Without smmu, the diff of MemFree between 4K and 64K measured on a high end aarch64 machine is 82M. + # Picking up 100M to cover this diff. And finally, we have "1G-4G:356M;4G-64G:420M;64G-:676M" + ((_delta += 100)) + else + ((_delta += 0)) + fi + _ck_cmdline=$(_crashkernel_add "$_ck_cmdline" "$_delta") elif [[ $_arch == "ppc64le" ]]; then if [[ $_dump_mode == "fadump" ]]; then _ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" diff --git a/kdumpctl b/kdumpctl index 5043a7b..827b595 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1678,12 +1678,14 @@ _is_bootloader_installed() _update_crashkernel() { - local _kernel _dump_mode _old_default_crashkernel _new_default_crashkernel _fadump_val _msg + local _kernel _kver _dump_mode _old_default_crashkernel _new_default_crashkernel _fadump_val _msg _kernel=$1 _dump_mode=$(get_dump_mode_by_kernel "$_kernel") _old_default_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) - _new_default_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_dump_mode") + _kver=$(parse_kver_from_path "$_kernel") + # The second argument is for the case of aarch64, where installing a 64k variant on a 4k kernel, or vice versa + _new_default_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_dump_mode" "$_kver") if [[ $_old_default_crashkernel != "$_new_default_crashkernel" ]]; then _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then From 7a2c4cbc3b10971c2a465ba2e465761e73390b74 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 13 Jun 2023 17:43:23 +0800 Subject: [PATCH 359/454] kdump-lib: Evaluate the memory consumption by smmu and mlx5 separately On 4k and 64k kernels, the typical consumption values for SMMU are 36MB and 384MB, respectively. Hence for 64k kernel, the consumption by smmu should be taken into account carefully. To do it by adding the extra 384MB value if installing a 64k kernel. The upper limit value 384MB is calculated according to the formula in the kernel smmu driver. As for mlx5 network cards, it is measured by a pratical test, 200M for 64k variant, 150M for 4k variant Signed-off-by: Pingfan Liu Reviewed-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump-lib.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 68431a0..9e818d3 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -829,6 +829,16 @@ get_recommend_size() echo "0M" } +has_mlx5() +{ + [[ -d /sys/bus/pci/drivers/mlx5_core ]] +} + +has_aarch64_smmu() +{ + ls /sys/devices/platform/arm-smmu-* 1> /dev/null 2>&1 +} + # $1 crashkernel="" # $2 delta in unit of MB _crashkernel_add() @@ -925,8 +935,14 @@ kdump_get_arch_recommend_crashkernel() # Without smmu, the diff of MemFree between 4K and 64K measured on a high end aarch64 machine is 82M. # Picking up 100M to cover this diff. And finally, we have "1G-4G:356M;4G-64G:420M;64G-:676M" ((_delta += 100)) + # On a 64K system, the extra 384MB is calculated by: cmdq_num * 16 bytes + evtq_num * 32B + priq_num * 16B + # While on a 4K system, it is negligible + has_aarch64_smmu && ((_delta += 384)) + #64k kernel, mlx5 consumes extra 188M memory, and choose 200M + has_mlx5 && ((_delta += 200)) else - ((_delta += 0)) + #4k kernel, mlx5 consumes extra 124M memory, and choose 150M + has_mlx5 && ((_delta += 150)) fi _ck_cmdline=$(_crashkernel_add "$_ck_cmdline" "$_delta") elif [[ $_arch == "ppc64le" ]]; then From 64d93c886f4cd1bc3008e8eb9dea7cdb8e8cc601 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Fri, 9 Jun 2023 16:04:29 +0800 Subject: [PATCH 360/454] kdumpctl: Fix the matching of plus symbol by grep's EREs After introducing 64k variant kernel on aarch64, an example kernel name looks like "vmlinuz-5.14.0-316.el9.aarch64+64k". To match the plus symbol, it demands an escape charater. Signed-off-by: Pingfan Liu Reviewed-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 3 +++ spec/kdumpctl_general_spec.sh | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/kdumpctl b/kdumpctl index 827b595..58c18d2 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1406,6 +1406,9 @@ _filter_grubby_kernel_str() _find_kernel_path_by_release() { local _release="$1" _grubby_kernel_str _kernel_path + + # Insert '/' before '+' to cope with grep's EREs + _release=${_release//+/\\+} _grubby_kernel_str=$(grubby --info ALL | grep -E "^kernel=.*$_release(\/\w+)?\"$") _kernel_path=$(_filter_grubby_kernel_str "$_grubby_kernel_str") if [[ -z $_kernel_path ]]; then diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index bb5755c..7304cd4 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -222,6 +222,23 @@ Describe 'kdumpctl' End End + Describe '_find_kernel_path_by_release()' + grubby() { + echo -e 'kernel="/boot/vmlinuz-6.2.11-200.fc37.x86_64"\nkernel="/boot/vmlinuz-5.14.0-322.el9.aarch64"\nkernel="/boot/vmlinuz-5.14.0-316.el9.aarch64+64k"' + } + + Parameters + # parameter answer + vmlinuz-6.2.11-200.fc37.x86_64 /boot/vmlinuz-6.2.11-200.fc37.x86_64 + vmlinuz-5.14.0-322.el9.aarch64 /boot/vmlinuz-5.14.0-322.el9.aarch64 + vmlinuz-5.14.0-316.el9.aarch64+64k /boot/vmlinuz-5.14.0-316.el9.aarch64+64k + End + It 'returns the kernel path for the given release' + When call _find_kernel_path_by_release "$1" + The output should equal "$2" + End + End + Describe 'parse_config()' bad_kdump_conf=$(mktemp -t bad_kdump_conf.XXXXXXXXXX) cleanup() { From 471c136481a7de4c21cef84aab82b97b57b3d0e4 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 14 Jun 2023 17:38:16 +0800 Subject: [PATCH 361/454] Release 2.0.26-7 Signed-off-by: Coiby Xu --- kexec-tools.spec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index e69a258..360b6c5 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 6%{?dist} +Release: 7%{?dist} License: GPLv2 Summary: The kexec/kdump userspace component @@ -396,6 +396,13 @@ fi %endif %changelog +* Wed Jun 14 2023 Coiby - 2.0.26-7 +- kdumpctl: Fix the matching of plus symbol by grep's EREs +- kdump-lib: Evaluate the memory consumption by smmu and mlx5 separately +- kdump-lib: add support for 64K aarch64 +- kdump-lib: Introduce parse_kver_from_path() to get kernel version from its path name +- kdump-lib: Introduce a help function _crashkernel_add() + * Fri Jun 02 2023 Timothée Ravier - 2.0.26-6 - Make binutils a recommend as it's only needed for UKI support From 8f243d2ab13a0d185e9bc7bbd2d1984731e353fd Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 15 Jun 2023 13:17:19 +0800 Subject: [PATCH 362/454] tests: generate correct RPM name Tests failed to run against Fedora 37 or newer cloud images because of the following error, It's a image with multiple partitions, using last partition as main partition 'xxx/tests/build/x86_64/kexec-tools-2.0.26-5.fc37.src.rpm' not found /dev/nbd0 disconnected make: *** [Makefile:73: xxx/tests/output/test-base-image] Error 1 This is because starting with Fedora 37, rpm changes its API, # Fedora >= 37 $ rpm -q --specfile kexec-tools.spec kexec-tools-2.0.26-5.fc37.src # Fedora 36 $ rpm -q --specfile kexec-tools.spec kexec-tools-2.0.26-5.fc36 The tests depends on rpm to generate correct RPM name. Fix this issue by removing the trailing .src from the output of "rpm -q --specfile". Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 05fda1d..45688ca 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -30,7 +30,7 @@ RPMDEFINE = --define '_sourcedir $(REPO)'\ KEXEC_TOOLS_SRC = $(filter-out $(REPO)/tests,$(wildcard $(REPO)/*)) KEXEC_TOOLS_TEST_SRC = $(wildcard $(REPO)/tests/scripts/**/*) -KEXEC_TOOLS_NVR = $(shell rpm $(RPMDEFINE) -q --specfile $(REPO)/$(SPEC) 2>/dev/null | grep -m 1 .) +KEXEC_TOOLS_NVR = $(shell rpm $(RPMDEFINE) -q --specfile $(REPO)/$(SPEC) 2>/dev/null | grep -m 1 . | sed -e 's#.src#.$(ARCH)#') KEXEC_TOOLS_RPM = $(BUILD_ROOT)/$(ARCH)/$(KEXEC_TOOLS_NVR).rpm all: $(TEST_ROOT)/output/test-base-image From 7cd799462e68393dffe0dc1f3a87c06440a96740 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 15 Jun 2023 13:17:20 +0800 Subject: [PATCH 363/454] tests: skip checking if the second partition has the boot label All the tests failed to run on the Fedora 37 host because the boot partition failed to be mounted and in turn the key kernel cmdline parameters like selinux=0 couldn't be added. The root problem is somehow running lsblk on the second partition returns an empty label unless we wait for enough time. Before figuring out the root cause, simply skip check that the second partition needs to have the boot label. Note the root problem can be produced by building a test image, cd tests ./scripts/build-image.sh Fedora-Cloud-Base-37-1.7.x86_64.qcow2 output_image scripts/build-scripts/base-image_test.sh Source image is qcow2, using snapshot... Formatting 'build/base-image1.building', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=5368709120 backing_file=Fedora-Cloud-Base-37-1.7.x86_64.qcow2 backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16 It's a image with multiple partitions, using last partition as main partition grep: /boot/grub2/grubenv: No such file or directory grub2-editenv: error: cannot open `/boot/grub2/grubenv.new': No such file or directory. /dev/nbd0 disconnected Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- tests/scripts/image-init-lib.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/scripts/image-init-lib.sh b/tests/scripts/image-init-lib.sh index 467f32f..b0af7f8 100644 --- a/tests/scripts/image-init-lib.sh +++ b/tests/scripts/image-init-lib.sh @@ -86,9 +86,9 @@ get_mountable_dev() { get_mount_boot() { local dev=$1 _second_part=${dev}p2 - if [[ $(lsblk -f $_second_part -n -o LABEL 2> /dev/null) == boot ]]; then - echo $_second_part - fi + # it's better to check if the 2nd partition has the boot label using lsblk + # but somehow this doesn't work starting with Fedora37 + echo $_second_part } From 17c26558d9b45d31755b9ed7f29a7ad291904740 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 15 Jun 2023 13:17:21 +0800 Subject: [PATCH 364/454] tests: use the default crashkernel value And with commit t5b31b099 ("Simplify the management of the kernel parameter crashkernel"), the default crashkernel value will be used for the kernel. But the test VM has a RAM of 768M thus this is no actual reserved memory for kdump. Even With the old crashkernel=224M, network dumping tests like nfs-kdump will fail out of memory when running against current Fedora Cloud images (>=F37). This patch address the above two issues by 1. increasing the RAM of test VM to 1G 2. installing the kernel-modules which contains the squashfs module in order to use the dracut squash module for kdump initrd. Thanks to the dracut squash module, now even crashkernel=192M (the default crashkernel value for RAM between 1G and 4G) works for network dumping. Another benefit brought by this change is the default crashkernel value can be tested as well. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- tests/scripts/build-scripts/base-image.sh | 3 +-- tests/scripts/test-lib.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/scripts/build-scripts/base-image.sh b/tests/scripts/build-scripts/base-image.sh index 62624e4..1d64cfb 100755 --- a/tests/scripts/build-scripts/base-image.sh +++ b/tests/scripts/build-scripts/base-image.sh @@ -3,8 +3,7 @@ img_inst_pkg grubby\ dnsmasq\ openssh openssh-server\ - dracut-network dracut-squash squashfs-tools ethtool snappy + dracut-network dracut-squash squashfs-tools ethtool snappy kernel-modules img_run_cmd "grubby --args systemd.journald.forward_to_console=1 systemd.log_target=console --update-kernel ALL" img_run_cmd "grubby --args selinux=0 --update-kernel ALL" -img_run_cmd "grubby --args crashkernel=224M --update-kernel ALL" diff --git a/tests/scripts/test-lib.sh b/tests/scripts/test-lib.sh index 8b24b2a..57b05d3 100644 --- a/tests/scripts/test-lib.sh +++ b/tests/scripts/test-lib.sh @@ -8,7 +8,7 @@ DEFAULT_QEMU_CMD="-nodefaults \ -nographic \ -smp 2 \ --m 768M \ +-m 1G \ -monitor none" _YELLOW='\033[1;33m' From dda81d72c2766167d48d3e505b95b2ca9b013039 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Mon, 19 Jun 2023 14:31:48 +0200 Subject: [PATCH 365/454] kdumpctl: Fix temporary directory location The temporary directory is currently created under the current working directory. That alone isn't ideal but works most of the time. However, it will fail when the current working directory is not writable. So make sure the directory is created within TMPDIR. Fixes: ea00b7d ("kdumpctl: Move temp file in get_kernel_size to global temp dir") Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kdumpctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 58c18d2..7e561fd 100755 --- a/kdumpctl +++ b/kdumpctl @@ -45,7 +45,7 @@ if ! dlog_init; then exit 1 fi -KDUMP_TMPDIR=$(mktemp -d kdump.XXXX) +KDUMP_TMPDIR=$(mktemp --tmpdir -d kdump.XXXX) trap ' ret=$?; rm -rf "$KDUMP_TMPDIR" From f3139012f290cbc35d262e1d6b24038b12b2c41d Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Tue, 20 Jun 2023 08:50:31 +0800 Subject: [PATCH 366/454] kdump-lib: Match 64k debug kernel in prepare_kdump_bootinfo() For kernel 64k variant, it terminates with substring 64k-debug, e.g. vmlinuz-5.14.0-327.el9.aarch64+64k-debug. Providing an extra matching pattern to filter out it. Signed-off-by: Pingfan Liu Reviewed-by: Coiby Xu --- kdump-lib.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 9e818d3..4290be3 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -614,7 +614,8 @@ prepare_kdump_bootinfo() return 1 fi - if [[ "$KDUMP_KERNEL" == *"+debug" ]]; then + # For 64k variant, e.g. vmlinuz-5.14.0-327.el9.aarch64+64k-debug + if [[ "$KDUMP_KERNEL" == *"+debug" || "$KDUMP_KERNEL" == *"64k-debug" ]]; then dwarn "Using debug kernel, you may need to set a larger crashkernel than the default value." fi From daa829f79e308e9d53060331f7721d3ee6b9f549 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Mon, 12 Jun 2023 17:17:43 +0800 Subject: [PATCH 367/454] spec: kdump/ppc64: make servicelog_notify silent when there are no errors There is confusing message in /var/log/anaconda/packaging.log when installing kexec-tools during the system installation on ppc64le: Event Notification Registration successful (id: 1) Make servicelog_notify slient when there are no erros. Signed-off-by: Lichen Liu Reviewed-by: Coiby Xu --- kexec-tools.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 360b6c5..d2143ad 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -269,7 +269,7 @@ touch /etc/kdump.conf %ifarch ppc64 ppc64le servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh 2>/dev/null -servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin +servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin >/dev/null %endif # This portion of the script is temporary. Its only here @@ -300,7 +300,7 @@ fi %preun %ifarch ppc64 ppc64le -servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh +servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh >/dev/null %endif %systemd_preun kdump.service From 52a034eb10f66f795622ff9c8bcfa474d0d30dee Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 4 Jul 2023 11:56:11 +0800 Subject: [PATCH 368/454] Use SPDX licence Convert to SPDX license by https://fedoraproject.org/wiki/Changes/SPDX_Licenses_Phase_2, # license-fedora2spdx GPLv2 GPL-2.0-only Signed-off-by: Coiby Xu --- kexec-tools.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index d2143ad..5a6648e 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -6,7 +6,7 @@ Name: kexec-tools Version: 2.0.26 Release: 7%{?dist} -License: GPLv2 +License: GPL-2.0-only Summary: The kexec/kdump userspace component Source0: http://kernel.org/pub/linux/utils/kernel/kexec/%{name}-%{version}.tar.xz From b725cdb45eb7d3b442204f3459cc3349c9e770ce Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Thu, 20 Jul 2023 08:42:47 +0000 Subject: [PATCH 369/454] Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild Signed-off-by: Fedora Release Engineering --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 5a6648e..ff8b496 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.26 -Release: 7%{?dist} +Release: 8%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -396,6 +396,9 @@ fi %endif %changelog +* Thu Jul 20 2023 Fedora Release Engineering - 2.0.26-8 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild + * Wed Jun 14 2023 Coiby - 2.0.26-7 - kdumpctl: Fix the matching of plus symbol by grep's EREs - kdump-lib: Evaluate the memory consumption by smmu and mlx5 separately From 4b7b7736eef8c682a8af07081d7f06eeb774172f Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Wed, 2 Aug 2023 20:36:48 +0530 Subject: [PATCH 370/454] Introduce a function to get reserved memory size The size of the reserved memory in the functions show_reserved_mem, check_crash_mem_reserved, and do_estimate are fetched from the sysfs node `/sys/kernel/kexec_crash_size`. However, in the case of fadump, the reserved area size is instead present in /sys/kernel/fadump/mem_reserved. For example: $ kdumpctl showmem kdump: Dump mode is fadump kdump: Reserved 0MB memory for crash kernel The above command showed 0MB for Reserved memory which is incorrect, the actual reservation was 2048MB. To resolve this issue a new helper function is introduced to fetch reserved memory size based on the dump mode. For "fadump" mode, it looks in `/sys/kernel/fadump/mem_reserved`, otherwise, it uses `/sys/kernel/kexec_crash_size`. And all functions that previously fetching reserved memory directly from `/sys/kernel/kexec_crash_size` sysfs node are now updated to use this new function to get the reserved memory size. With the fix in place, the `kdumpctl showmem` command will now display correct reserved memory size. $ kdumpctl showmem kdump: Dump mode is fadump kdump: Reserved 2048MB memory for crash kernel Signed-off-by: Sourabh Jain Reported-by: Sachin P Bappalige Reviewed-by: Coiby Xu --- kdump-lib.sh | 15 ++++++++++++++- kdumpctl | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 4290be3..16238c5 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -344,11 +344,24 @@ is_mount_in_dracut_args() [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] } +get_reserved_mem_size() +{ + local reserved_mem_size=0 + + if is_fadump_capable; then + reserved_mem_size=$(< /sys/kernel/fadump/mem_reserved) + else + reserved_mem_size=$(< /sys/kernel/kexec_crash_size) + fi + + echo "$reserved_mem_size" +} + check_crash_mem_reserved() { local mem_reserved - mem_reserved=$(< /sys/kernel/kexec_crash_size) + mem_reserved=$(get_reserved_mem_size) if [[ $mem_reserved -eq 0 ]]; then derror "No memory reserved for crash kernel" return 1 diff --git a/kdumpctl b/kdumpctl index 7e561fd..1f7f4ce 100755 --- a/kdumpctl +++ b/kdumpctl @@ -856,7 +856,7 @@ show_reserved_mem() local mem local mem_mb - mem=$(< /sys/kernel/kexec_crash_size) + mem=$(get_reserved_mem_size) mem_mb=$((mem / 1024 / 1024)) dinfo "Reserved ${mem_mb}MB memory for crash kernel" @@ -1270,7 +1270,7 @@ do_estimate() # The default pre-reserved crashkernel value baseline_size=$((baseline * size_mb)) # Current reserved crashkernel size - reserved_size=$(< /sys/kernel/kexec_crash_size) + reserved_size=$(get_reserved_mem_size) # A pre-estimated value for userspace usage and kernel # runtime allocation, 64M should good for most cases runtime_size=$((64 * size_mb)) From 98c7c6ee6aa6b5c7983f568bb359d7860ed27fd0 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 31 Aug 2023 11:29:43 +0800 Subject: [PATCH 371/454] [packit] 2.0.27 upstream release Upstream tag: v2.0.27 Upstream commit: 17590eed --- .packit.yaml | 16 ++++++++++++++++ README.packit | 3 +++ kexec-tools.spec | 7 +++++-- sources | 4 ++-- 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 .packit.yaml create mode 100644 README.packit diff --git a/.packit.yaml b/.packit.yaml new file mode 100644 index 0000000..88fcda6 --- /dev/null +++ b/.packit.yaml @@ -0,0 +1,16 @@ +# See the documentation for more information: +# https://packit.dev/docs/configuration/ + +specfile_path: kexec-tools.spec + +# add or remove files that should be synced +files_to_sync: + - kexec-tools.spec + - .packit.yaml + +# name in upstream package repository or registry (e.g. in PyPI) +upstream_package_name: kexec-tools +# downstream (Fedora) RPM package name +downstream_package_name: kexec-tools + +upstream_tag_template: v{version} diff --git a/README.packit b/README.packit new file mode 100644 index 0000000..159f693 --- /dev/null +++ b/README.packit @@ -0,0 +1,3 @@ +This repository is maintained by packit. +https://packit.dev/ +The file was generated using packit 0.79.0. diff --git a/kexec-tools.spec b/kexec-tools.spec index ff8b496..897b6ff 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,8 +4,8 @@ %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools -Version: 2.0.26 -Release: 8%{?dist} +Version: 2.0.27 +Release: 1%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -396,6 +396,9 @@ fi %endif %changelog +* Thu Aug 31 2023 Coiby Xu - 2.0.27-1 +- kexec-tools 2.0.27 (Simon Horman) + * Thu Jul 20 2023 Fedora Release Engineering - 2.0.26-8 - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild diff --git a/sources b/sources index d684233..54a591c 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ -SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 -SHA512 (kexec-tools-2.0.26.tar.xz) = afecb64f50a0a2e553712d7e6e4d48e0dc745e4140983a33a10cce931e6aeddaff9c4a3385fbaf7ab9ff7b3b905d932fbce1e0e37aa2c35d5c1e61277140dee9 +SHA512 (kexec-tools-2.0.27.tar.xz) = 30b5ef7c2075dfd11fd1c3c33abe6b60673400257668d60145be08a2472356c7191a0810095da0fa32e327b9806a7578c73129ac0550d26c28ea6571c88c7b3c SHA512 (makedumpfile-1.7.2.tar.gz) = 324e303dd5f507703f66e2bd5dc9d24f9f50ba797be70c05702008ba77078f61ffcc884796ddf9ab737de1d124c3a9d881ab5ce4f3f459690ec00055af25ea9e +SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 From fc7c65312a5bef115ce40818bf43ddd3b01b8958 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Thu, 17 Aug 2023 16:38:35 +0530 Subject: [PATCH 372/454] powerpc: update fadump sysfs node path The fadump sysfs nodes /sys/kernel/fadump_[enabled|registered], have been relocated to /sys/kernel/fadump/[enabled|registered] by kernel commits d418b19f34ed ("powerpc/fadump: Reorganize /sys/kernel/fadump_* sysfs files"). To ensure compatibility, symbolic links were added for each relocated sysfs entry. Nonetheless, note that these symbolic links might be removed later, as they have been deprecated by kernel commit 3f5f1f22ef10 ("Documentation/ABI: Mark /sys/kernel/fadump_* sysfs files deprecated") This patch updates the scripts to use the updated fadump sysfs files. Signed-off-by: Sourabh Jain Reviewed-by: Philipp Rudo --- 98-kexec.rules.ppc64 | 2 +- fadump-howto.txt | 2 +- kdump-lib.sh | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/98-kexec.rules.ppc64 b/98-kexec.rules.ppc64 index a1c00a9..e9db276 100644 --- a/98-kexec.rules.ppc64 +++ b/98-kexec.rules.ppc64 @@ -17,6 +17,6 @@ GOTO="kdump_reload_end" LABEL="kdump_reload_cpu" -RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; ! test -f /sys/kernel/fadump_enabled || cat /sys/kernel/fadump_enabled | grep 0 || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'" +RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; ! test -f /sys/kernel/fadump/enabled || cat /sys/kernel/fadump/enabled | grep 0 || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'" LABEL="kdump_reload_end" diff --git a/fadump-howto.txt b/fadump-howto.txt index 9773f78..2fe76cf 100644 --- a/fadump-howto.txt +++ b/fadump-howto.txt @@ -137,7 +137,7 @@ Then, start up kdump as well: # systemctl start kdump.service This should turn on the firmware assisted functionality in kernel by -echo'ing 1 to /sys/kernel/fadump_registered, leaving the system ready +echo'ing 1 to /sys/kernel/fadump/registered, leaving the system ready to capture a vmcore upon crashing. For journaling filesystems like XFS an additional step is required to ensure bootloader does not pick the older initrd (without vmcore capture scripts): diff --git a/kdump-lib.sh b/kdump-lib.sh index 16238c5..99c726b 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -8,8 +8,8 @@ else . /lib/kdump/kdump-lib-initramfs.sh fi -FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" -FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" +FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump/enabled" +FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump/registered" is_uki() { From 026edc2b592c1ce6389acc67520a9e8a3d2d5735 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:36 +0200 Subject: [PATCH 373/454] Fix various shellcheck findings This includes fixes for SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns. SC2005 (style): Useless echo? Instead of 'echo $(cmd)', just use 'cmd'. SC2162 (info): read without -r will mangle backslashes. SC2086 (info): Double quote to prevent globbing and word splitting. SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly). In addition add some source hints to prevent false positive findings. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdump-lib.sh | 10 +++++----- kdumpctl | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 99c726b..634bd22 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -197,7 +197,7 @@ get_bind_mount_source() local _fsroot _src_nofsroot _mnt=$(df "$1" | tail -1 | awk '{print $NF}') - _path=${1#$_mnt} + _path=${1#"$_mnt"} _src=$(get_mount_info SOURCE target "$_mnt" -f) _opt=$(get_mount_info OPTIONS target "$_mnt" -f) @@ -214,7 +214,7 @@ get_bind_mount_source() echo "$_mnt$_path" && return fi - _fsroot=${_src#${_src_nofsroot}[} + _fsroot=${_src#"${_src_nofsroot}"[} _fsroot=${_fsroot%]} _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) @@ -223,7 +223,7 @@ get_bind_mount_source() local _subvol _subvol=${_opt#*subvol=} _subvol=${_subvol%,*} - _fsroot=${_fsroot#$_subvol} + _fsroot=${_fsroot#"$_subvol"} fi echo "$_mnt$_fsroot$_path" } @@ -270,7 +270,7 @@ kdump_get_persistent_dev() dev=$(blkid -L "${dev#LABEL=}") ;; esac - echo $(get_persistent_dev "$dev") + get_persistent_dev "$dev" } is_ostree() @@ -823,7 +823,7 @@ get_recommend_size() while read -r -d , range; do # need to use non-default IFS as double spaces are used as a # single delimiter while commas aren't... - IFS=, read start start_unit end end_unit size <<< \ + IFS=, read -r start start_unit end end_unit size <<< \ "$(echo "$range" | sed -n "s/\([0-9]\+\)\([GT]\?\)-\([0-9]*\)\([GT]\?\):\([0-9]\+[MG]\)/\1,\2,\3,\4,\5/p")" # aka. 102400T diff --git a/kdumpctl b/kdumpctl index 1f7f4ce..7844488 100755 --- a/kdumpctl +++ b/kdumpctl @@ -29,14 +29,17 @@ if [[ -f /etc/sysconfig/kdump ]]; then fi [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut -. $dracutbasedir/dracut-functions.sh +# shellcheck source=/dev/null +. "$dracutbasedir"/dracut-functions.sh if [[ ${__SOURCED__:+x} ]]; then KDUMP_LIB_PATH=. else KDUMP_LIB_PATH=/lib/kdump fi +# shellcheck source=./kdump-lib.sh . $KDUMP_LIB_PATH/kdump-lib.sh +# shellcheck source=./kdump-logger.sh . $KDUMP_LIB_PATH/kdump-logger.sh #initiate the kdump logger @@ -247,7 +250,7 @@ restore_default_initrd() if [[ $default_checksum != "$backup_checksum" ]]; then dwarn "WARNING: checksum mismatch! Can't restore original initrd.." else - rm -f $INITRD_CHECKSUM_LOCATION + rm -f "$INITRD_CHECKSUM_LOCATION" if mv "$DEFAULT_INITRD_BAK" "$DEFAULT_INITRD"; then derror "Restoring original initrd as fadump mode is disabled." sync -f "$DEFAULT_INITRD" @@ -497,6 +500,7 @@ check_drivers_modified() # If it's dump target is on block device, detect the block driver _target=$(get_block_dump_target) if [[ -n $_target ]]; then + # shellcheck disable=SC2317 _record_block_drivers() { local _drivers From bbda12a5acbd30a58ad6b3eb4e1313045f402646 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:37 +0200 Subject: [PATCH 374/454] kdump-lib: make is_zstd_command_available more generic There is value to use the function in other places as well. For example it can be used to check whether optional dependencies, like grubby, are installed. Thus make it more generic so it can be reused in later commits. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdump-lib.sh | 4 ++-- mkdumprd | 2 +- mkfadumprd | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 634bd22..d314157 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -48,9 +48,9 @@ is_squash_available() done } -is_zstd_command_available() +has_command() { - [[ -x "$(command -v zstd)" ]] + [[ -x $(command -v "$1") ]] } dracut_have_option() diff --git a/mkdumprd b/mkdumprd index f93874d..4feac28 100644 --- a/mkdumprd +++ b/mkdumprd @@ -443,7 +443,7 @@ handle_default_dump_target if ! have_compression_in_dracut_args; then if is_squash_available && dracut_have_option "--squash-compressor"; then add_dracut_arg "--squash-compressor" "zstd" - elif is_zstd_command_available; then + elif has_command zstd; then add_dracut_arg "--compress" "zstd" fi fi diff --git a/mkfadumprd b/mkfadumprd index 719e150..dd6840f 100755 --- a/mkfadumprd +++ b/mkfadumprd @@ -64,7 +64,7 @@ _dracut_isolate_args=( # Use zstd compression method, if available if ! have_compression_in_dracut_args; then - if is_zstd_command_available; then + if has_command zstd; then _dracut_isolate_args+=(--compress zstd) fi fi From f01fef4016734096dc3df0f247cec5f9fe2cd8ed Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:38 +0200 Subject: [PATCH 375/454] kdump-lib: simplify _get_kdump_kernel_version Only check whether modules for a given kernel version are installed instead of searching for a kernel image. It's safer to assume that every kernel uses kernel modules compared to that it follows certain naming conventions. Furthermore it is much more lightweight and thus allows to determine the KDUMP_KERNELVER much earlier for every command in kdumpctl. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdump-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index d314157..55c29bd 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -599,7 +599,7 @@ _get_kdump_kernel_version() _version_nondebug=${_version%+debug} _version_nondebug=${_version_nondebug%-debug} - if [[ -f "$(prepare_kdump_kernel "$_version_nondebug")" ]]; then + if _is_valid_kver "$_version_nondebug"; then dinfo "Use of debug kernel detected. Trying to use $_version_nondebug" echo "$_version_nondebug" else From b9738affc9b9b2a5d32206431811a6c8f9efb773 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:39 +0200 Subject: [PATCH 376/454] kdumpctl: drop _get_current_running_kernel_path _get_current_running_kernel_path is identical to _find_kernel_path_by_release $(uname -r) so simply use this instead of defining a new function. While at it simplify reset_crashkernel slightly. This changes the behavior of the function for the case when KDUMP_KERNELVER is defined but no kernel with this version is installed. Before, the missing kernel is silently ignored and the currently running kernel is used instead. Now, kdumpctl will exit with an error. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdumpctl | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/kdumpctl b/kdumpctl index 7844488..8cd423c 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1422,18 +1422,6 @@ _find_kernel_path_by_release() echo -n "$_kernel_path" } -_get_current_running_kernel_path() -{ - local _release _path - - _release=$(uname -r) - if _path=$(_find_kernel_path_by_release "$_release"); then - echo -n "$_path" - else - return 1 - fi -} - _update_kernel_cmdline() { local _kernel_path=$1 _crashkernel=$2 _dump_mode=$3 _fadump_val=$4 @@ -1628,14 +1616,11 @@ reset_crashkernel() # - use KDUMP_KERNELVER if it's defined # - use current running kernel if [[ -z $_grubby_kernel_path ]]; then - if [[ -z $KDUMP_KERNELVER ]] || - ! _kernel_path=$(_find_kernel_path_by_release "$KDUMP_KERNELVER"); then - if ! _kernel_path=$(_get_current_running_kernel_path); then - derror "no running kernel found" - exit 1 - fi + [[ -n $KDUMP_KERNELVER ]] || KDUMP_KERNELVER=$(uname -r) + if ! _kernels=$(_find_kernel_path_by_release "$KDUMP_KERNELVER"); then + derror "no kernel for version $KDUMP_KERNELVER found" + exit 1 fi - _kernels=$_kernel_path else _kernels=$(_get_all_kernels_from_grubby "$_grubby_kernel_path") fi From 1049e1c79c15865a008f1eb001f8357c03a80e53 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:40 +0200 Subject: [PATCH 377/454] kdumpctl: drop condrestart subcommand condrestart is a left over from the time of SysVinit that is no longer needed since the kexec-tools switched to systemd (10c91a1 ("Removing sysvinit files") plus the one before). What's especially intriguing is that from the beginning (0112f36 ("- Add a kdump sysconfig file and init script - Spec file additions for pre/post install/uninstall")) the sub-command never did any actual work (other than not returning an error). Thus simply remove the condrestart sub-command. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdumpctl | 2 -- 1 file changed, 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index 8cd423c..7ef23a8 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1795,8 +1795,6 @@ main() rebuild) rebuild ;; - condrestart) ;; - propagate) propagate_ssh_key ;; From f5785c60aaf349c7264c422f73f287874049f7b4 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:41 +0200 Subject: [PATCH 378/454] kdumpctl: simplify _update_kernel_cmdline _update_kernel_cmdline handles two cmdline parameters at once. This does not only make the function itself but also its callers more complicated than necessary. For example in _update_crashkernel the fadump gets "updated" to the value that has been read from grubby. Thus simplify _update_kernel_cmdline to only update one parameter at once. While at it shorten some variable named in the callers. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdumpctl | 108 ++++++++++++----------- spec/kdumpctl_manage_crashkernel_spec.sh | 5 ++ spec/kdumpctl_reset_crashkernel_spec.sh | 5 ++ 3 files changed, 67 insertions(+), 51 deletions(-) diff --git a/kdumpctl b/kdumpctl index 7ef23a8..5088c32 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1424,21 +1424,33 @@ _find_kernel_path_by_release() _update_kernel_cmdline() { - local _kernel_path=$1 _crashkernel=$2 _dump_mode=$3 _fadump_val=$4 + local _kernel _param _old _new + + _kernel="$1" + _param="$2" + _old="$3" + _new="$4" + + # _new = "" removes a _param, so _new = _old = "" is fine + [[ -n "$_new" ]] && [[ "$_old" == "$_new" ]] && return 1 if is_ostree; then - if rpm-ostree kargs | grep -q "crashkernel="; then - rpm-ostree kargs --replace="crashkernel=$_crashkernel" + if [[ -z "$_new" ]]; then + rpm-ostree kargs --delete="$_param=$_old" + elif [[ -n "$_old" ]]; then + rpm-ostree kargs --replace="$_param=$_new" else - rpm-ostree kargs --append="crashkernel=$_crashkernel" + rpm-ostree kargs --append="$_param=$_new" + fi + elif has_command grubby; then + if [[ -n "$_new" ]]; then + grubby --update-kernel "$_kernel" --args "$_param=$_new" + else + grubby --update-kernel "$_kernel" --remove-args "$_param" fi else - grubby --args "crashkernel=$_crashkernel" --update-kernel "$_kernel_path" - if [[ $_dump_mode == kdump ]]; then - grubby --remove-args="fadump" --update-kernel "$_kernel_path" - else - grubby --args="fadump=$_fadump_val" --update-kernel "$_kernel_path" - fi + derror "Unable to update kernel command line" + exit 1 fi # Don't use "[[ CONDITION ]] && COMMAND" which returns 1 under false CONDITION @@ -1530,9 +1542,11 @@ _read_kernel_arg_in_grub_etc_default() reset_crashkernel() { - local _opt _val _dump_mode _fadump_val _reboot _grubby_kernel_path _kernel _kernels - local _old_crashkernel _new_crashkernel _new_dump_mode _crashkernel_changed - local _new_fadump_val _old_fadump_val _what_is_updated + local _opt _val _fadump_val _reboot _grubby_kernel_path _kernel _kernels + local _dump_mode _new_dump_mode + local _has_changed _needs_reboot + local _old_ck _new_ck + local _old_fadump _new_fadump for _opt in "$@"; do case "$_opt" in @@ -1570,14 +1584,10 @@ reset_crashkernel() # modifying the kernel command line so there is no need for kexec-tools # to repeat it. if is_ostree; then - _old_crashkernel=$(rpm-ostree kargs | sed -n -E 's/.*(^|\s)crashkernel=(\S*).*/\2/p') - _new_dump_mode=kdump - _new_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") - if [[ $_old_crashkernel != "$_new_crashkernel" ]]; then - _update_kernel_cmdline "" "$_new_crashkernel" "$_new_dump_mode" "" - if [[ $_reboot == yes ]]; then - systemctl reboot - fi + _old_ck=$(rpm-ostree kargs | sed -n -E 's/.*(^|\s)crashkernel=(\S*).*/\2/p') + _new_ck=$(kdump_get_arch_recommend_crashkernel kdump) + if _update_kernel_cmdline "" crashkernel "$_old_ck" "$_new_ck"; then + [[ $_reboot == yes ]] && systemctl reboot fi return fi @@ -1626,35 +1636,33 @@ reset_crashkernel() fi for _kernel in $_kernels; do + _has_changed="" if [[ -z $_dump_mode ]]; then _new_dump_mode=$(get_dump_mode_by_kernel "$_kernel") - _new_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") - _new_fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + _new_ck=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") + _new_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump) else _new_dump_mode=$_dump_mode - _new_crashkernel=$_crashkernel - _new_fadump_val=$_fadump_val + _new_ck=$_crashkernel + _new_fadump=$_fadump_val fi - _old_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) - _old_fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) - if [[ $_old_crashkernel != "$_new_crashkernel" || $_old_fadump_val != "$_new_fadump_val" ]]; then - _update_kernel_cmdline "$_kernel" "$_new_crashkernel" "$_new_dump_mode" "$_new_fadump_val" - if [[ $_reboot != yes ]]; then - if [[ $_old_crashkernel != "$_new_crashkernel" ]]; then - _what_is_updated="Updated crashkernel=$_new_crashkernel" - else - # This case happens only when switching between fadump=on and fadump=nocma - _what_is_updated="Updated fadump=$_new_fadump_val" - fi - dwarn "$_what_is_updated for kernel=$_kernel. Please reboot the system for the change to take effect." - fi - _crashkernel_changed=yes + _old_ck=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) + _old_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump) + if _update_kernel_cmdline "$_kernel" fadump "$_old_fadump" "$_new_fadump"; then + _has_changed="Updated fadump=$_new_fadump" + fi + if _update_kernel_cmdline "$_kernel" crashkernel "$_old_ck" "$_new_ck"; then + _has_changed="Updated crashkernel=$_new_ck" + fi + if [[ -n "$_has_changed" ]]; then + _needs_reboot=1 + dwarn "$_has_changed for kernel=$_kernel. Please reboot the system for the change to take effect." fi done - if [[ $_reboot == yes && $_crashkernel_changed == yes ]]; then - reboot + if [[ $_reboot == yes && $_needs_reboot == 1 ]]; then + systemctl reboot fi } @@ -1670,21 +1678,19 @@ _is_bootloader_installed() _update_crashkernel() { - local _kernel _kver _dump_mode _old_default_crashkernel _new_default_crashkernel _fadump_val _msg + local _kernel _kver _dump_mode _msg + local _old_ck _new_ck _kernel=$1 _dump_mode=$(get_dump_mode_by_kernel "$_kernel") - _old_default_crashkernel=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) + _old_ck=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) _kver=$(parse_kver_from_path "$_kernel") # The second argument is for the case of aarch64, where installing a 64k variant on a 4k kernel, or vice versa - _new_default_crashkernel=$(kdump_get_arch_recommend_crashkernel "$_dump_mode" "$_kver") - if [[ $_old_default_crashkernel != "$_new_default_crashkernel" ]]; then - _fadump_val=$(get_grub_kernel_boot_parameter "$_kernel" fadump) - if _update_kernel_cmdline "$_kernel" "$_new_default_crashkernel" "$_dump_mode" "$_fadump_val"; then - _msg="For kernel=$_kernel, crashkernel=$_new_default_crashkernel now. Please reboot the system for the change to take effet." - _msg+=" Note if you don't want kexec-tools to manage the crashkernel kernel parameter, please set auto_reset_crashkernel=no in /etc/kdump.conf." - dinfo "$_msg" - fi + _new_ck=$(kdump_get_arch_recommend_crashkernel "$_dump_mode" "$_kver") + if _update_kernel_cmdline "$_kernel" crashkernel "$_old_ck" "$_new_ck"; then + _msg="For kernel=$_kernel, crashkernel=$_new_ck now. Please reboot the system for the change to take effect." + _msg+=" Note if you don't want kexec-tools to manage the crashkernel kernel parameter, please set auto_reset_crashkernel=no in /etc/kdump.conf." + dinfo "$_msg" fi } diff --git a/spec/kdumpctl_manage_crashkernel_spec.sh b/spec/kdumpctl_manage_crashkernel_spec.sh index 9078347..bae3f31 100644 --- a/spec/kdumpctl_manage_crashkernel_spec.sh +++ b/spec/kdumpctl_manage_crashkernel_spec.sh @@ -52,6 +52,11 @@ Describe 'Management of the kernel crashkernel parameter.' @grubby --no-etc-grub-update --grub2 --config-file="$GRUB_CFG" --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" } + # The mocking breaks has_command. Mock it as well to fix the tests. + has_command() { + [[ "$1" == grubby ]] + } + Describe "When kexec-tools have its default crashkernel updated, " Context "if kexec-tools is updated alone, " diff --git a/spec/kdumpctl_reset_crashkernel_spec.sh b/spec/kdumpctl_reset_crashkernel_spec.sh index 28d9277..8fb4385 100644 --- a/spec/kdumpctl_reset_crashkernel_spec.sh +++ b/spec/kdumpctl_reset_crashkernel_spec.sh @@ -29,6 +29,11 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' @grubby --no-etc-grub-update --grub2 --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" } + # The mocking breaks has_command. Mock it as well to fix the tests. + has_command() { + [[ "$1" == grubby ]] + } + Describe "Test the kdump dump mode " uname() { if [[ $1 == '-m' ]]; then From 099434b9932fd8a82a3e021ec8e8c482b3698c01 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:42 +0200 Subject: [PATCH 379/454] kdumpctl: Prevent option --fadump on non-PPC in reset_crashkernel Prevent the --fadump option to be used on non-PPC systems. This not only prevents user errors but also guarantees that _dump_mode and _fadump_val are empty on these systems. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdumpctl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kdumpctl b/kdumpctl index 5088c32..113d8bc 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1551,6 +1551,10 @@ reset_crashkernel() for _opt in "$@"; do case "$_opt" in --fadump=*) + if [[ $(uname -m) != ppc64le ]]; then + derror "Option --fadump only valid on PPC" + exit 1 + fi _val=${_opt#*=} if _dump_mode=$(get_dump_mode_by_fadump_val $_val); then _fadump_val=$_val @@ -1592,12 +1596,7 @@ reset_crashkernel() return fi - # For non-ppc64le systems, the dump mode is always kdump since only ppc64le - # has FADump. - if [[ -z $_dump_mode && $(uname -m) != ppc64le ]]; then - _dump_mode=kdump - _fadump_val=off - fi + [[ $(uname -m) != ppc64le ]] && _dump_mode=kdump # If the dump mode is determined, we can also know the default crashkernel value if [[ -n $_dump_mode ]]; then From 8175924e89aefbc91e5f0b40213e0ed1ea394283 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:43 +0200 Subject: [PATCH 380/454] kdumpctl: Stop updating grub config in reset_crashkernel With multiple kernel variants on the same architecture, e.g. the 4k and 64k kernel on aarch64, we can no longer assume that the crashkernel value for the currently running kernel will work for all installed kernels. This also means that we can no longer update the grub config as we don't know which value to set it to. Thus get the crashkernel value for each kernel and stop updating the grub config. While at it merge the _new_fadump and _fadump_val variables and remove _read_kernel_arg_in_grub_etc_default which has no user. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdumpctl | 96 ++----------------------- spec/kdumpctl_general_spec.sh | 67 ----------------- spec/kdumpctl_reset_crashkernel_spec.sh | 10 --- 3 files changed, 5 insertions(+), 168 deletions(-) diff --git a/kdumpctl b/kdumpctl index 113d8bc..6e4685f 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1480,69 +1480,9 @@ _get_all_kernels_from_grubby() echo -n "$_kernels" } -GRUB_ETC_DEFAULT="/etc/default/grub" -# Update a kernel parameter in default grub conf -# -# If a value is specified, it will be inserted in the end. Otherwise it -# would remove given kernel parameter. -# -# Note this function doesn't address the following cases, -# 1. The kernel ignores everything on the command line after a '--'. So -# simply adding the new entry to the end will fail if the cmdline -# contains a --. -# 2. If the value for a parameter contains spaces it can be quoted using -# double quotes, for example param="value with spaces". This will -# break the [^[:space:]\"] regex for the value. -# 3. Dashes and underscores in the parameter name are equivalent. So -# some_parameter and some-parameter are identical. -# 4. Some parameters, e.g. efivar_ssdt, can be given multiple times. -# 5. Some kernel parameters, e.g. quiet, doesn't have value -# -# $1: the name of the kernel command line parameter -# $2: new value. If empty, given parameter would be removed -_update_kernel_arg_in_grub_etc_default() -{ - local _para=$1 _val=$2 _para_val - - if [[ $(uname -m) == s390x ]]; then - return - fi - - if [[ -n $_val ]]; then - _para_val="$_para=$_val" - fi - - # Update the command line /etc/default/grub, i.e. - # on the line that starts with 'GRUB_CMDLINE_LINUX=', - # 1) remove $para=$val if the it's the first arg - # 2) remove all occurences of $para=$val - # 3) insert $_para_val to end - # 4) remove duplicate spaces left over by 1) or 2) or 3) - # 5) remove space at the beginning of the string left over by 1) or 2) or 3) - # 6) remove space at the end of the string left over by 1) or 2) or 3) - sed -i -E "/^GRUB_CMDLINE_LINUX=/ { - s/\"${_para}=[^[:space:]\"]*/\"/g; - s/[[:space:]]+${_para}=[^[:space:]\"]*/ /g; - s/\"$/ ${_para_val}\"/ - s/[[:space:]]+/ /g; - s/(\")[[:space:]]+/\1/g; - s/[[:space:]]+(\")/\1/g; - }" "$GRUB_ETC_DEFAULT" -} - -# Read the kernel arg in default grub conf. - -# Note reading a kernel parameter that doesn't have a value isn't supported. -# -# $1: the name of the kernel command line parameter -_read_kernel_arg_in_grub_etc_default() -{ - sed -n -E "s/^GRUB_CMDLINE_LINUX=.*[[:space:]\"]${1}=([^[:space:]\"]*).*$/\1/p" "$GRUB_ETC_DEFAULT" -} - reset_crashkernel() { - local _opt _val _fadump_val _reboot _grubby_kernel_path _kernel _kernels + local _opt _val _reboot _grubby_kernel_path _kernel _kernels local _dump_mode _new_dump_mode local _has_changed _needs_reboot local _old_ck _new_ck @@ -1555,13 +1495,12 @@ reset_crashkernel() derror "Option --fadump only valid on PPC" exit 1 fi - _val=${_opt#*=} - if _dump_mode=$(get_dump_mode_by_fadump_val $_val); then - _fadump_val=$_val - else + _new_fadump=${_opt#*=} + if ! _dump_mode=$(get_dump_mode_by_fadump_val $_new_fadump); then derror "failed to determine dump mode" exit fi + [[ "$_new_fadump" == off ]] && _new_fadump="" ;; --kernel=*) _val=${_opt#*=} @@ -1598,29 +1537,6 @@ reset_crashkernel() [[ $(uname -m) != ppc64le ]] && _dump_mode=kdump - # If the dump mode is determined, we can also know the default crashkernel value - if [[ -n $_dump_mode ]]; then - _crashkernel=$(kdump_get_arch_recommend_crashkernel "$_dump_mode") - fi - - # If --kernel-path=ALL, update GRUB_CMDLINE_LINUX in /etc/default/grub. - # - # An exception case is when the ppc64le user doesn't specify the fadump value. - # In this case, the dump mode would be determined by parsing the kernel - # command line of the kernel(s) to be updated thus don't update GRUB_CMDLINE_LINUX. - # - # The following code has been simplified because of what has been done early, - # - set the dump mode as kdump for non-ppc64le cases - # - retrieved the default crashkernel value for given dump mode - if [[ $_grubby_kernel_path == ALL && -n $_dump_mode ]]; then - _update_kernel_arg_in_grub_etc_default crashkernel "$_crashkernel" - # remove the fadump if fadump is disabled - if [[ $_fadump_val == off ]]; then - _fadump_val="" - fi - _update_kernel_arg_in_grub_etc_default fadump "$_fadump_val" - fi - # If kernel-path not specified, either # - use KDUMP_KERNELVER if it's defined # - use current running kernel @@ -1638,15 +1554,13 @@ reset_crashkernel() _has_changed="" if [[ -z $_dump_mode ]]; then _new_dump_mode=$(get_dump_mode_by_kernel "$_kernel") - _new_ck=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") _new_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump) else _new_dump_mode=$_dump_mode - _new_ck=$_crashkernel - _new_fadump=$_fadump_val fi _old_ck=$(get_grub_kernel_boot_parameter "$_kernel" crashkernel) + _new_ck=$(kdump_get_arch_recommend_crashkernel "$_new_dump_mode") _old_fadump=$(get_grub_kernel_boot_parameter "$_kernel" fadump) if _update_kernel_cmdline "$_kernel" fadump "$_old_fadump" "$_new_fadump"; then _has_changed="Updated fadump=$_new_fadump" diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index 7304cd4..dcac2f8 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -155,73 +155,6 @@ Describe 'kdumpctl' End End - Describe '_update_kernel_arg_in_grub_etc_default()' - GRUB_ETC_DEFAULT=/tmp/default_grub - - cleanup() { - rm -rf "$GRUB_ETC_DEFAULT" - } - AfterAll 'cleanup' - - Context 'when the given parameter is in different positions' - Parameters - "crashkernel=222M fadump=on rhgb quiet" crashkernel 333M - " fadump=on crashkernel=222M rhgb quiet" crashkernel 333M - "fadump=on rhgb quiet crashkernel=222M" crashkernel 333M - "fadump=on rhgb quiet" crashkernel 333M - "fadump=on foo=bar1 rhgb quiet" foo bar2 - End - - It 'should update the kernel parameter correctly' - echo 'GRUB_CMDLINE_LINUX="'"$1"'"' >$GRUB_ETC_DEFAULT - When call _update_kernel_arg_in_grub_etc_default "$2" "$3" - # the updated kernel parameter should appear in the end - The contents of file $GRUB_ETC_DEFAULT should include "$2=$3\"" - End - End - - It 'should only update the given parameter and not update the parameter that has the given parameter as suffix' - echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT - _ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M - When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val" - The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\"" - The contents of file $GRUB_ETC_DEFAULT should include "ckcrashkernel=222M" - End - - It 'should be able to handle the cases of there are multiple crashkernel entries' - echo 'GRUB_CMDLINE_LINUX="fadump=on rhgb quiet crashkernel=101M crashkernel=222M"' >$GRUB_ETC_DEFAULT - _ck_val=1G-4G:192M,4G-64G:256M,64G-102400T:512M - When call _update_kernel_arg_in_grub_etc_default crashkernel "$_ck_val" - The contents of file $GRUB_ETC_DEFAULT should include "crashkernel=$_ck_val\"" - The contents of file $GRUB_ETC_DEFAULT should not include "crashkernel=222M" - End - - Context 'when it removes a kernel parameter' - - It 'should remove all values for given arg' - echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M fadump=on crashkernel=222M"' >$GRUB_ETC_DEFAULT - When call _update_kernel_arg_in_grub_etc_default crashkernel - The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="fadump=on"' - End - - It 'should not remove args that have the given arg as suffix' - echo 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT - When call _update_kernel_arg_in_grub_etc_default crashkernel - The contents of file $GRUB_ETC_DEFAULT should equal 'GRUB_CMDLINE_LINUX="ckcrashkernel=33M ckcrashkernel=222M"' - End - End - - End - - Describe '_read_kernel_arg_in_grub_etc_default()' - GRUB_ETC_DEFAULT=/tmp/default_grub - It 'should read the value for given arg' - echo 'GRUB_CMDLINE_LINUX="crashkernel=33M crashkernel=11M ckcrashkernel=222M"' >$GRUB_ETC_DEFAULT - When call _read_kernel_arg_in_grub_etc_default crashkernel - The output should equal '11M' - End - End - Describe '_find_kernel_path_by_release()' grubby() { echo -e 'kernel="/boot/vmlinuz-6.2.11-200.fc37.x86_64"\nkernel="/boot/vmlinuz-5.14.0-322.el9.aarch64"\nkernel="/boot/vmlinuz-5.14.0-316.el9.aarch64+64k"' diff --git a/spec/kdumpctl_reset_crashkernel_spec.sh b/spec/kdumpctl_reset_crashkernel_spec.sh index 8fb4385..2e3b2ba 100644 --- a/spec/kdumpctl_reset_crashkernel_spec.sh +++ b/spec/kdumpctl_reset_crashkernel_spec.sh @@ -111,11 +111,6 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' fi } - _update_kernel_arg_in_grub_etc_default() { - # don't modify /etc/default/grub during the test - echo _update_kernel_arg_in_grub_etc_default "$@" - } - kdump_crashkernel=$(get_default_crashkernel kdump) fadump_crashkernel=$(get_default_crashkernel fadump) Context "when no --kernel specified" @@ -141,7 +136,6 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' grubby --args crashkernel=$ck --update-kernel ALL Specify 'kdumpctl should warn the user that crashkernel has been udpated' When call reset_crashkernel --kernel=ALL --fadump=on - The line 1 of output should include "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel" The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1" The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel2" End @@ -200,8 +194,6 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' grubby --args fadump=on --update-kernel ALL Specify 'fadump=on to fadump=nocma' When call reset_crashkernel --kernel=ALL --fadump=nocma - The line 1 of output should equal "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel" - The line 2 of output should equal "_update_kernel_arg_in_grub_etc_default fadump nocma" The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel1" The error should include "Updated crashkernel=$fadump_crashkernel for kernel=$kernel2" End @@ -213,8 +205,6 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' Specify 'fadump=nocma to fadump=on' When call reset_crashkernel --kernel=ALL --fadump=on - The line 1 of output should equal "_update_kernel_arg_in_grub_etc_default crashkernel $fadump_crashkernel" - The line 2 of output should equal "_update_kernel_arg_in_grub_etc_default fadump on" The error should include "Updated fadump=on for kernel=$kernel1" End From 755ba199a77c464d4ba301725ba500f8397dfe42 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:44 +0200 Subject: [PATCH 381/454] kdump.conf: Remove option override_resettable When override_resettable was introduced in 2013 with 4b850d2 ("Check if block device as dump target is resettable") it was forgotten to add the new option to check_config (today the function is called parse_config). So if a user would have set override_resettable check_config would have returned an error ("Invalid kdump config option override_resettable") and starting the kdump service would have failed. As there has been no bug report in the last ~10 years it is safe to assume that the option was never used. Thus simply remove the option. Fixes: 4b850d2 ("Check if block device as dump target is resettable") Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- gen-kdump-conf.sh | 6 ------ kdump.conf.5 | 8 ------- mkdumprd | 55 ----------------------------------------------- 3 files changed, 69 deletions(-) diff --git a/gen-kdump-conf.sh b/gen-kdump-conf.sh index 4abcd39..a8e7fdd 100755 --- a/gen-kdump-conf.sh +++ b/gen-kdump-conf.sh @@ -157,12 +157,6 @@ generate() # force_no_rebuild and force_rebuild options are mutually # exclusive and they should not be set to 1 simultaneously. # -# override_resettable <0 | 1> -# - Usually an unresettable block device can't be a dump target. -# Specifying 1 when you want to dump even though the block -# target is unresettable -# By default, it is 0, which will not try dumping destined to fail. -# # dracut_args # - Pass extra dracut options when rebuilding kdump initrd. # diff --git a/kdump.conf.5 b/kdump.conf.5 index ec28552..9117aa7 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -218,14 +218,6 @@ force_no_rebuild and force_rebuild options are mutually exclusive and they should not be set to 1 simultaneously. .RE -.B override_resettable <0 | 1> -.RS -Usually an unresettable block device can't be a dump target. Specifying 1 means -that even though the block target is unresettable, the user wants to try dumping anyway. -By default, it's set to 0, which will not try something destined to fail. -.RE - - .B dracut_args .RS Kdump uses dracut to generate initramfs for second kernel. This option diff --git a/mkdumprd b/mkdumprd index 4feac28..31c4b76 100644 --- a/mkdumprd +++ b/mkdumprd @@ -24,7 +24,6 @@ fi SSH_KEY_LOCATION=$DEFAULT_SSHKEY SAVE_PATH=$(get_save_path) -OVERRIDE_RESETTABLE=0 extra_modules="" dracut_args=(--add kdumpbase --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict --hostonly-nics '' --aggressive-strip -o "plymouth resume ifcfg earlykdump") @@ -309,56 +308,6 @@ handle_default_dump_target() check_size fs "$_target" } -# $1: function name -for_each_block_target() -{ - local dev majmin - - for dev in $(get_kdump_targets); do - [[ -b $dev ]] || continue - majmin=$(get_maj_min "$dev") - check_block_and_slaves "$1" "$majmin" && return 1 - done - - return 0 -} - -#judge if a specific device with $1 is unresettable -#return false if unresettable. -is_unresettable() -{ - local path device resettable=1 - - path="/sys/$(udevadm info --query=all --path="/sys/dev/block/$1" | awk '/^P:/ {print $2}' | sed -e 's/\(cciss[0-9]\+\/\).*/\1/g' -e 's/\/block\/.*$//')/resettable" - if [[ -f $path ]]; then - resettable="$(< "$path")" - [[ $resettable -eq 0 ]] && [[ $OVERRIDE_RESETTABLE -eq 0 ]] && { - device=$(udevadm info --query=all --path="/sys/dev/block/$1" | awk -F= '/DEVNAME/{print $2}') - derror "Error: Can not save vmcore because device $device is unresettable" - return 0 - } - fi - - return 1 -} - -#check if machine is resettable. -#return true if resettable -check_resettable() -{ - local _target _override_resettable - - _override_resettable=$(kdump_get_conf_val override_resettable) - OVERRIDE_RESETTABLE=${_override_resettable:-$OVERRIDE_RESETTABLE} - if [ "$OVERRIDE_RESETTABLE" != "0" ] && [ "$OVERRIDE_RESETTABLE" != "1" ]; then - perror_exit "override_resettable value '$OVERRIDE_RESETTABLE' is invalid" - fi - - for_each_block_target is_unresettable && return - - return 1 -} - check_crypt() { local _dev @@ -370,10 +319,6 @@ check_crypt() done } -if ! check_resettable; then - exit 1 -fi - if ! check_crypt; then dwarn "Warning: Encrypted device is in dump path, which is not recommended, see kexec-kdump-howto.txt for more details." fi From 8e0b3598c1120b1ab182297c04be4c420760dbb1 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:45 +0200 Subject: [PATCH 382/454] spec: Clean up handling of dracut files Currently the dracut modules are first prepared in a temporary directory before they are moved to modules.d. All the preparation work can be done by a single call to 'install' per file. Thus get rid off the indirection and install the dracut modules directly to modules.d. While at it merge the three macros to remove the prefix into one. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kexec-tools.spec | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 897b6ff..a75c02c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -228,39 +228,28 @@ mkdir -p $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ install -m 644 makedumpfile-%{mkdf_ver}/eppic_scripts/* $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ %endif -%define remove_dracut_prefix() %(echo -n %1|sed 's/.*dracut-//g') -%define remove_dracut_early_kdump_prefix() %(echo -n %1|sed 's/.*dracut-early-kdump-//g') -%define remove_dracut_fadump_prefix() %(echo -n %1|sed 's/.*dracut-fadump-//g') +%define dracutdir %{_prefix}/lib/dracut/modules.d +%define remove_prefix() %(echo -n %2|sed 's/.*%1-//g') # deal with dracut modules -mkdir -p -m755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase -cp %{SOURCE100} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE100}} -cp %{SOURCE101} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE101}} -cp %{SOURCE102} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE102}} -cp %{SOURCE104} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE104}} -cp %{SOURCE106} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE106}} -cp %{SOURCE107} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE107}} -chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE100}} -chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99kdumpbase/%{remove_dracut_prefix %{SOURCE101}} -mkdir -p -m755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump -cp %{SOURCE108} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump/%{remove_dracut_prefix %{SOURCE108}} -cp %{SOURCE109} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump/%{remove_dracut_early_kdump_prefix %{SOURCE109}} -chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump/%{remove_dracut_prefix %{SOURCE108}} -chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99earlykdump/%{remove_dracut_early_kdump_prefix %{SOURCE109}} +mkdir -p -m755 $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase +install -m 755 %{SOURCE100} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE100}} +install -m 755 %{SOURCE101} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE101}} +install -m 644 %{SOURCE102} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE102}} +install -m 644 %{SOURCE104} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE104}} +install -m 644 %{SOURCE106} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE106}} +install -m 644 %{SOURCE107} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE107}} + +mkdir -p -m755 $RPM_BUILD_ROOT/%{dracutdir}/99earlykdump +install -m 755 %{SOURCE108} $RPM_BUILD_ROOT/%{dracutdir}/99earlykdump/%{remove_prefix dracut %{SOURCE108}} +install -m 755 %{SOURCE109} $RPM_BUILD_ROOT/%{dracutdir}/99earlykdump/%{remove_prefix dracut-early-kdump %{SOURCE109}} + %ifarch ppc64 ppc64le -mkdir -p -m755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit -cp %{SOURCE200} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE200}} -cp %{SOURCE201} $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE201}} -chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE200}} -chmod 755 $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/99zz-fadumpinit/%{remove_dracut_fadump_prefix %{SOURCE201}} +mkdir -p -m755 $RPM_BUILD_ROOT/%{dracutdir}/99zz-fadumpinit +install -m 755 %{SOURCE200} $RPM_BUILD_ROOT/%{dracutdir}/99zz-fadumpinit/%{remove_prefix dracut-fadump %{SOURCE200}} +install -m 755 %{SOURCE201} $RPM_BUILD_ROOT/%{dracutdir}/99zz-fadumpinit/%{remove_prefix dracut-fadump %{SOURCE201}} %endif - -%define dracutlibdir %{_prefix}/lib/dracut -#and move the custom dracut modules to the dracut directory -mkdir -p $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ -mv $RPM_BUILD_ROOT/etc/kdump-adv-conf/kdump_dracut_modules/* $RPM_BUILD_ROOT/%{dracutlibdir}/modules.d/ - %post # Initial installation %systemd_post kdump.service @@ -363,7 +352,7 @@ fi %config %{_udevrulesdir} %{_udevrulesdir}/../kdump-udev-throttler %endif -%{dracutlibdir}/modules.d/* +%{dracutdir}/* %dir %{_localstatedir}/crash %dir %{_sysconfdir}/kdump %dir %{_sysconfdir}/kdump/pre.d From d89459c5ec701e2dec8d475a1e18a87893e3e23d Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:46 +0200 Subject: [PATCH 383/454] spec: Silence unversioned Obsolete warning rpmbuild throws a warning with line 80: It's not recommended to have unversioned Obsoletes: Obsoletes: diskdumputils netdump kexec-tools-eppic In that diskdump and netdump were last used in RHEL4 and kexec-tools-eppic was removed with Fedora 22. There is no supported update path in which a current package could replace one of these three. Thus simply drop the Obsoletes. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kexec-tools.spec | 3 --- 1 file changed, 3 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index a75c02c..ef75fd0 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -75,9 +75,6 @@ BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel b BuildRequires: pkgconfig intltool gettext BuildRequires: systemd-rpm-macros BuildRequires: automake autoconf libtool -%ifarch %{ix86} x86_64 ppc64 ppc s390x ppc64le -Obsoletes: diskdumputils netdump kexec-tools-eppic -%endif %ifnarch s390x Requires: systemd-udev%{?_isa} From 64f2827a4bfa3f26974972f2f5a4477eec58f221 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:47 +0200 Subject: [PATCH 384/454] kdump-lib: Harden _crashkernel_add _crashkernel_add currently always assumes the good case, i.e. that the value of the crashkernel parameter has the correct syntax and that the delta added is a number. Both doesn't have to be true when the values are provided by users. Thus add some additional checks. Furthermore require the delta to have a explicit unit, i.e. no longer assume that is in megabytes, i.e. 100 -> 100M. Signed-off-by: Philipp Rudo Reviewed-by: Pingfan Liu --- kdump-lib.sh | 155 +++++++++++++++++++++++++++++------------ spec/kdump-lib_spec.sh | 38 ++++++---- 2 files changed, 134 insertions(+), 59 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 55c29bd..042ac87 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -853,62 +853,125 @@ has_aarch64_smmu() ls /sys/devices/platform/arm-smmu-* 1> /dev/null 2>&1 } -# $1 crashkernel="" -# $2 delta in unit of MB -_crashkernel_add() +is_memsize() { [[ "$1" =~ ^[+-]?[0-9]+[KkMmGg]?$ ]]; } + +# range defined for crashkernel parameter +# i.e. -[] +is_memrange() { - local _ck _add _entry _ret - local _range _size _offset + is_memsize "${1%-*}" || return 1 + [[ -n ${1#*-} ]] || return 0 + is_memsize "${1#*-}" +} - _ck="$1" - _add="$2" - _ret="" +to_bytes() +{ + local _s - if [[ "$_ck" == *@* ]]; then - _offset="@${_ck##*@}" - _ck=${_ck%@*} - elif [[ "$_ck" == *,high ]] || [[ "$_ck" == *,low ]]; then - _offset=",${_ck##*,}" - _ck=${_ck%,*} + _s="$1" + is_memsize "$_s" || return 1 + + case "${_s: -1}" in + K|k) + _s=${_s::-1} + _s="$((_s * 1024))" + ;; + M|m) + _s=${_s::-1} + _s="$((_s * 1024 * 1024))" + ;; + G|g) + _s=${_s::-1} + _s="$((_s * 1024 * 1024 * 1024))" + ;; + *) + ;; + esac + echo "$_s" +} + +memsize_add() +{ + local -a units=("" "K" "M" "G") + local i a b + + a=$(to_bytes "$1") || return 1 + b=$(to_bytes "$2") || return 1 + i=0 + + (( a += b )) + while :; do + [[ $(( a / 1024 )) -eq 0 ]] && break + [[ $(( a % 1024 )) -ne 0 ]] && break + [[ $(( ${#units[@]} - 1 )) -eq $i ]] && break + + (( a /= 1024 )) + (( i += 1 )) + done + + echo "${a}${units[$i]}" +} + +_crashkernel_parse() +{ + local ck entry + local range size offset + + ck="$1" + + if [[ "$ck" == *@* ]]; then + offset="@${ck##*@}" + ck=${ck%@*} + elif [[ "$ck" == *,high ]] || [[ "$ck" == *,low ]]; then + offset=",${ck##*,}" + ck=${ck%,*} else - _offset='' + offset='' fi - while read -d , -r _entry; do - [[ -n "$_entry" ]] || continue - if [[ "$_entry" == *:* ]]; then - _range=${_entry%:*} - _size=${_entry#*:} + while read -d , -r entry; do + [[ -n "$entry" ]] || continue + if [[ "$entry" == *:* ]]; then + range=${entry%:*} + size=${entry#*:} else - _range="" - _size=${_entry} + range="" + size=${entry} fi - case "${_size: -1}" in - K) - _size=${_size::-1} - _size="$((_size + (_add * 1024)))K" - ;; - M) - _size=${_size::-1} - _size="$((_size + _add))M" - ;; - G) - _size=${_size::-1} - _size="$((_size * 1024 + _add))M" - ;; - *) - _size="$((_size + (_add * 1024 * 1024)))" - ;; - esac + echo "$size;$range;" + done <<< "$ck," + echo ";;$offset" +} - [[ -n "$_range" ]] && _ret+="$_range:" - _ret+="$_size," - done <<< "$_ck," +# $1 crashkernel command line parameter +# $2 size to be added +_crashkernel_add() +{ + local ck delta ret + local range size offset - _ret=${_ret%,} - [[ -n "$_offset" ]] && _ret+=$_offset - echo "$_ret" + ck="$1" + delta="$2" + ret="" + + while IFS=';' read -r size range offset; do + if [[ -n "$offset" ]]; then + ret="${ret%,}$offset" + break + fi + + [[ -n "$size" ]] || continue + if [[ -n "$range" ]]; then + is_memrange "$range" || return 1 + ret+="$range:" + fi + + size=$(memsize_add "$size" "$delta") || return 1 + ret+="$size," + done < <( _crashkernel_parse "$ck") + + echo "${ret%,}" } # get default crashkernel @@ -958,7 +1021,7 @@ kdump_get_arch_recommend_crashkernel() #4k kernel, mlx5 consumes extra 124M memory, and choose 150M has_mlx5 && ((_delta += 150)) fi - _ck_cmdline=$(_crashkernel_add "$_ck_cmdline" "$_delta") + _ck_cmdline=$(_crashkernel_add "$_ck_cmdline" "${_delta}M") elif [[ $_arch == "ppc64le" ]]; then if [[ $_dump_mode == "fadump" ]]; then _ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" diff --git a/spec/kdump-lib_spec.sh b/spec/kdump-lib_spec.sh index 81f0f86..814f961 100644 --- a/spec/kdump-lib_spec.sh +++ b/spec/kdump-lib_spec.sh @@ -49,21 +49,33 @@ Describe 'kdump-lib' End Describe "_crashkernel_add()" - Context "when the input parameter is '1G-4G:256M,4G-64G:320M,64G-:576M'" - delta=100 + Context "For valid input values" Parameters - "1G-4G:256M,4G-64G:320M,64G-:576M" "1G-4G:356M,4G-64G:420M,64G-:676M" - "1G-4G:256M,4G-64G:320M,64G-:576M@4G" "1G-4G:356M,4G-64G:420M,64G-:676M@4G" - "1G-4G:1G,4G-64G:2G,64G-:3G@4G" "1G-4G:1124M,4G-64G:2148M,64G-:3172M@4G" - "1G-4G:10000K,4G-64G:20000K,64G-:40000K@4G" "1G-4G:112400K,4G-64G:122400K,64G-:142400K@4G" - "300M,high" "400M,high" - "300M,low" "400M,low" - "500M@1G" "600M@1G" + "1G-4G:256M,4G-64G:320M,64G-:576M" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M" + "1G-4G:256M,4G-64G:320M,64G-:576M@4G" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M@4G" + "1G-4G:1G,4G-64G:2G,64G-:3G@4G" "100M" "1G-4G:1124M,4G-64G:2148M,64G-:3172M@4G" + "1G-4G:10000K,4G-64G:20000K,64G-:40000K@4G" "100M" "1G-4G:112400K,4G-64G:122400K,64G-:142400K@4G" + "1,high" "1" "2,high" + "1K,low" "1" "1025,low" + "1M@1G" "1k" "1025K@1G" + "500M@1G" "-100m" "400M@1G" + "1099511627776" "0" "1024G" End - It "should add delta to the values after ':'" - - When call _crashkernel_add "$1" "$delta" - The output should equal "$2" + It "should add delta to every value after ':'" + When call _crashkernel_add "$1" "$2" + The output should equal "$3" + End + End + Context "For invalid input values" + Parameters + "1G-4G:256M.4G-64G:320M" "100M" + "foo" "1" + "1" "bar" + End + It "shall return an error" + When call _crashkernel_add "$1" "$2" + The output should equal "" + The status should be failure End End End From 00c37d8c2c2d6112f9ff81eab2cfb930c0b0cac5 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:48 +0200 Subject: [PATCH 385/454] spec: Drop special handling for IA64 machines The two systems are IA64 based which is no longer supported by Fedora and was only supported in RHEL up to RHEL5. So it is safe to simply drop the special handling. In case it is still wanted nevertheless the special handling should be added to kdump-lib.sh:prepare_cmdline rather than editing the sysconfig in the spec file. Signed-off-by: Philipp Rudo --- kexec-tools.spec | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index ef75fd0..e51d496 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -258,28 +258,6 @@ servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh 2>/d servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin >/dev/null %endif -# This portion of the script is temporary. Its only here -# to fix up broken boxes that require special settings -# in /etc/sysconfig/kdump. It will be removed when -# These systems are fixed. - -if [ -d /proc/bus/mckinley ] -then - # This is for HP zx1 machines - # They require machvec=dig on the kernel command line - sed -e's/\(^KDUMP_COMMANDLINE_APPEND.*\)\("$\)/\1 machvec=dig"/' \ - /etc/sysconfig/kdump > /etc/sysconfig/kdump.new - mv /etc/sysconfig/kdump.new /etc/sysconfig/kdump -elif [ -d /proc/sgi_sn ] -then - # This is for SGI SN boxes - # They require the --noio option to kexec - # since they don't support legacy io - sed -e's/\(^KEXEC_ARGS.*\)\("$\)/\1 --noio"/' \ - /etc/sysconfig/kdump > /etc/sysconfig/kdump.new - mv /etc/sysconfig/kdump.new /etc/sysconfig/kdump -fi - %postun %systemd_postun_with_restart kdump.service From 2f52973feb59e9aee3a7d9dbac45b1fa1e513889 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Wed, 6 Sep 2023 10:49:49 +0200 Subject: [PATCH 386/454] unit tests: Fix parse_config test case The test case for parse_config creates a default kdump.conf in the pwd. This fails when the pwd is read only. Thus move the default kdump.conf to /tmp just like it is done for the "bad" kdump.conf. This also allows to reuse the temporary file used for the "bad" case. Signed-off-by: Philipp Rudo --- spec/kdumpctl_general_spec.sh | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index dcac2f8..243aeca 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -173,16 +173,14 @@ Describe 'kdumpctl' End Describe 'parse_config()' - bad_kdump_conf=$(mktemp -t bad_kdump_conf.XXXXXXXXXX) + KDUMP_CONFIG_FILE=$(mktemp -t kdump_conf.XXXXXXXXXX) cleanup() { - rm -f "$bad_kdump_conf" - rm -f kdump.conf + rm -f "$KDUMP_CONFIG_FILE" } AfterAll 'cleanup' It 'should not be happy with unkown option in kdump.conf' - KDUMP_CONFIG_FILE="$bad_kdump_conf" - echo blabla > "$bad_kdump_conf" + echo blabla > "$KDUMP_CONFIG_FILE" When call parse_config The status should be failure The stderr should include 'Invalid kdump config option blabla' @@ -191,10 +189,7 @@ Describe 'kdumpctl' Parameters:value aarch64 ppc64le s390x x86_64 It 'should be happy with the default kdump.conf' - ./gen-kdump-conf.sh "$1" > kdump.conf - # shellcheck disable=SC2034 - # override the KDUMP_CONFIG_FILE variable - KDUMP_CONFIG_FILE=./kdump.conf + ./gen-kdump-conf.sh "$1" > "$KDUMP_CONFIG_FILE" When call parse_config The status should be success End From 8bf11dc3f6e418d7513260eb5ab0fa8c63797b62 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 14 Sep 2023 15:27:48 +0800 Subject: [PATCH 387/454] unit tests: fix test failures "The param /boot/boot/vmlinuz-xxx is incorrect" Currently, some tests failed with "The param /boot/boot/vmlinuz-xxx is incorrect", for example, [root@fedora kexec-tools]# shellspec spec/kdumpctl_manage_reset_spec.sh Examples: 1) kdumpctl reset-crashkernel [--kernel] [--fadump] Test the kdump dump mode --kernel=ALL kdumpctl should warn the user that crashkernel has been udpated When call reset_crashkernel --kernel=ALL 1.1) The error should include Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/vmlinuz-5.15.6-100.fc34.x86_64 expected "The param /boot/boot/vmlinuz-5.15.6-100.fc34.x86_64 is incorrect The param /boot/boot/vmlinuz-5.15.6-100.fc34.x86_64 is incorrect kdump: Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/boot/vmlinuz-5.15.6-100.fc34.x86_64. Please reboot the system for the change to take effect. The param /boot/boot/vmlinuz-5.14.14-200.fc34.x86_64 is incorrect The param /boot/boot/vmlinuz-5.14.14-200.fc34.x86_64 is incorrect kdump: Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/boot/vmlinuz-5.14.14-200.fc34.x86_64. Please reboot the system for the change to take effect. The param /boot/boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b is incorrect The param /boot/boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b is incorrect kdump: Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/boot/vmlinuz-0-rescue-e986846f63134c7295458cf36300ba5b. Please reboot the system for the change to take effect." to include "Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/vmlinuz-5.15.6-100.fc34.x86_64" # spec/kdumpctl_reset_crashkernel_spec.sh:69 This happens because when a system has a boot partition, grubby automatically prefixes a path with "/boot". The current boot loader entries used for tests already has the prefix "/boot" in the path and prefixing a path again will cause the above problem. grubby uses "mountpoint -q /boot" to tell if there is a boot partition. This patch mocks mountpoint so grubby knows the boot loader entries are for a system without a boot partition. Note this patch also avoids another error seen in the setup phase of the test "The param /boot/vmlinuz-xxx is incorrect". I believe this error is a bug of "grubby --update-kernel" in testing mode because running the grubby in normal mode actually works and "grubby --info=/boot/vmlinuz-*" also works in testing mode, [root@fedora support]# grubby --no-etc-grub-update --grub2 --bad-image-okay --env=grub_env -b boot_load_entries --args crashkernel=333M --update-kernel=/boot/vmlinuz-5.15.6-100.fc34.x86_64 The param /boot/vmlinuz-5.15.6-100.fc34.x86_64 is incorrect [root@fedora support]# grubby --no-etc-grub-update --grub2 --bad-image-okay --env=grub_env -b boot_load_entries --info=/boot/vmlinuz-5.15.6-100.fc34.x86_64 index=0 kernel="/boot/boot/vmlinuz-5.15.6-100.fc34.x86_64" [root@fedora support]]# grubby --args crashkernel=333M --update-kernel=/boot/vmlinuz-6.0.7-301.fc37.x86_64 && echo "succeed" succeed Reviewed-by: Philipp Rudo Signed-off-by: Coiby Xu --- spec/kdumpctl_manage_crashkernel_spec.sh | 8 +++++++- spec/kdumpctl_reset_crashkernel_spec.sh | 8 +++++++- spec/support/bin/@grubby | 3 --- 3 files changed, 14 insertions(+), 5 deletions(-) delete mode 100755 spec/support/bin/@grubby diff --git a/spec/kdumpctl_manage_crashkernel_spec.sh b/spec/kdumpctl_manage_crashkernel_spec.sh index bae3f31..3255d9a 100644 --- a/spec/kdumpctl_manage_crashkernel_spec.sh +++ b/spec/kdumpctl_manage_crashkernel_spec.sh @@ -42,6 +42,12 @@ Describe 'Management of the kernel crashkernel parameter.' rm -rf "$KDUMP_SPEC_TEST_RUN_DIR" } + # the boot loader entries are for a system without a boot partition, mock + # mountpoint to let grubby know it + Mock mountpoint + exit 1 + End + grubby() { # - --no-etc-grub-update, not update /etc/default/grub # - --bad-image-okay, don't check the validity of the image @@ -49,7 +55,7 @@ Describe 'Management of the kernel crashkernel parameter.' # the default /boot/grub2/grubenv # - --bls-directory, specify custom BootLoaderSpec config files to avoid # modifying the default /boot/loader/entries - @grubby --no-etc-grub-update --grub2 --config-file="$GRUB_CFG" --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" + /usr/sbin/grubby --no-etc-grub-update --grub2 --config-file="$GRUB_CFG" --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" } # The mocking breaks has_command. Mock it as well to fix the tests. diff --git a/spec/kdumpctl_reset_crashkernel_spec.sh b/spec/kdumpctl_reset_crashkernel_spec.sh index 2e3b2ba..88ff5a9 100644 --- a/spec/kdumpctl_reset_crashkernel_spec.sh +++ b/spec/kdumpctl_reset_crashkernel_spec.sh @@ -19,6 +19,12 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' BeforeAll 'setup' AfterAll 'cleanup' + # the boot loader entries are for a system without a boot partition, mock + # mountpoint to let grubby know it + Mock mountpoint + exit 1 + End + grubby() { # - --no-etc-grub-update, not update /etc/default/grub # - --bad-image-okay, don't check the validity of the image @@ -26,7 +32,7 @@ Describe 'kdumpctl reset-crashkernel [--kernel] [--fadump]' # the default /boot/grub2/grubenv # - --bls-directory, specify custom BootLoaderSpec config files to avoid # modifying the default /boot/loader/entries - @grubby --no-etc-grub-update --grub2 --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" + /usr/sbin/grubby --no-etc-grub-update --grub2 --bad-image-okay --env="$KDUMP_SPEC_TEST_RUN_DIR"/env_temp -b "$KDUMP_SPEC_TEST_RUN_DIR"/boot_load_entries "$@" } # The mocking breaks has_command. Mock it as well to fix the tests. diff --git a/spec/support/bin/@grubby b/spec/support/bin/@grubby deleted file mode 100755 index 2a9b33f..0000000 --- a/spec/support/bin/@grubby +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -e -. "$SHELLSPEC_SUPPORT_BIN" -invoke grubby "$@" From fe6eb30e6756d3c13bb7485a08f066b18cd1594b Mon Sep 17 00:00:00 2001 From: Nayna Jain Date: Tue, 3 Oct 2023 23:41:46 -0400 Subject: [PATCH 388/454] powerpc: update kdumpctl to remove deletion of kernel signing key once loaded Kernel signing key is deleted once kdump is loaded. This causes confusion in debugging since key is no longer visible. Unless someone knows how kdumpctl script works, it is difficult to find out how kdump could be loaded when there is no key on .ima keyring. Remove deletion of kernel signing key once loaded. And then to prevent multiple loading of same key when kdump service is disabled/enabled, update key description field as well. Suggested-by: Mimi Zohar Signed-off-by: Nayna Jain Reviewed-by: Philipp Rudo --- kdumpctl | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/kdumpctl b/kdumpctl index 6e4685f..3d5d6dd 100755 --- a/kdumpctl +++ b/kdumpctl @@ -678,19 +678,7 @@ function load_kdump_kernel_key() return fi - KDUMP_KEY_ID=$(keyctl padd asymmetric kernelkey-$RANDOM %:.ima < "/usr/share/doc/kernel-keys/$KDUMP_KERNELVER/kernel-signing-ppc.cer") -} - -# remove a previously loaded key. There's no real security implication -# to leaving it around, we choose to do this because it makes it easier -# to be idempotent and so as to reduce the potential for confusion. -function remove_kdump_kernel_key() -{ - if [[ -z $KDUMP_KEY_ID ]]; then - return - fi - - keyctl unlink "$KDUMP_KEY_ID" %:.ima + keyctl padd asymmetric "" %:.ima < "/usr/share/doc/kernel-keys/$KDUMP_KERNELVER/kernel-signing-ppc.cer" } # Load the kdump kernel specified in /etc/sysconfig/kdump @@ -742,8 +730,6 @@ load_kdump() set +x exec 2>&12 12>&- - remove_kdump_kernel_key - if [[ $ret == 0 ]]; then dinfo "kexec: loaded kdump kernel" return 0 From 4fa17b2ee4a6089cddd3c4b929840f4faf72ff98 Mon Sep 17 00:00:00 2001 From: Nayna Jain Date: Tue, 3 Oct 2023 23:41:47 -0400 Subject: [PATCH 389/454] powerpc: update kdumpctl to load kernel signing key for fadump On secure boot enabled systems with static keys, kexec with kexec_file_load(-s) fails as "Permission Denied" when fadump is enabled. Similar to kdump, load kernel signing key for fadump as well. Reported-by: Sachin P Bappalige Signed-off-by: Nayna Jain --- dracut-early-kdump.sh | 5 ----- kdump-lib.sh | 9 +++++++++ kdumpctl | 14 ++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh index 044f741..4fd8e90 100755 --- a/dracut-early-kdump.sh +++ b/dracut-early-kdump.sh @@ -45,11 +45,6 @@ early_kdump_load() EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") - if is_secure_boot_enforced; then - dinfo "Secure Boot is enabled. Using kexec file based syscall." - 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. diff --git a/kdump-lib.sh b/kdump-lib.sh index 042ac87..ae39c23 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -501,6 +501,15 @@ prepare_kexec_args() fi fi fi + + # For secureboot enabled machines, use new kexec file based syscall. + # Old syscall will always fail as it does not have capability to do + # kernel signature verification. + if is_secure_boot_enforced; then + dinfo "Secure Boot is enabled. Using kexec file based syscall." + kexec_args="$kexec_args -s" + fi + echo "$kexec_args" } diff --git a/kdumpctl b/kdumpctl index 3d5d6dd..b6d5994 100755 --- a/kdumpctl +++ b/kdumpctl @@ -690,14 +690,6 @@ load_kdump() KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") KDUMP_COMMANDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}") - # For secureboot enabled machines, use new kexec file based syscall. - # Old syscall will always fail as it does not have capability to - # to kernel signature verification. - if is_secure_boot_enforced; then - dinfo "Secure Boot is enabled. Using kexec file based syscall." - KEXEC_ARGS="$KEXEC_ARGS -s" - load_kdump_kernel_key - fi if is_uki "$KDUMP_KERNEL"; then uki=$KDUMP_KERNEL @@ -984,6 +976,12 @@ start_fadump() start_dump() { + # On secure boot enabled Power systems, load kernel signing key on .ima for signature + # verification using kexec file based syscall. + if [[ "$(uname -m)" == ppc64le ]] && is_secure_boot_enforced; then + load_kdump_kernel_key + fi + if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then start_fadump else From 7af94019cf53b94919316cd786f9cbecf338a1da Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 10 Oct 2023 15:58:01 +0800 Subject: [PATCH 390/454] [packit] 2.0.27 upstream release Upstream tag: v2.0.27 Upstream commit: 2495ccfc --- 0001-kexec-tools-2.0.27.git.patch | 30 +++ 0002-build-fix-tarball-creation.patch | 43 +++++ ...ble-arm64-kexec_load-for-zboot-image.patch | 134 ++++++++++++++ ...oot-add-loongarch-kexec_load-support.patch | 171 ++++++++++++++++++ README.packit | 2 +- kexec-tools.spec | 15 ++ 6 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 0001-kexec-tools-2.0.27.git.patch create mode 100644 0002-build-fix-tarball-creation.patch create mode 100644 0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch create mode 100644 0004-zboot-add-loongarch-kexec_load-support.patch diff --git a/0001-kexec-tools-2.0.27.git.patch b/0001-kexec-tools-2.0.27.git.patch new file mode 100644 index 0000000..3939f62 --- /dev/null +++ b/0001-kexec-tools-2.0.27.git.patch @@ -0,0 +1,30 @@ +From 056c179cd3c2af0c3bd2762a8a3bfd1340278e9e Mon Sep 17 00:00:00 2001 +From: Simon Horman +Date: Fri, 1 Sep 2023 09:37:24 +0200 +Subject: [PATCH 1/4] kexec-tools 2.0.27.git + +Add .git to version so it doesn't look like a release. +This is just so when people build code from git it can +be identified as such from the version string. + +Signed-off-by: Simon Horman +--- + configure.ac | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/configure.ac b/configure.ac +index 192976c..352eefe 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -4,7 +4,7 @@ dnl + dnl + + dnl ---Required +-AC_INIT(kexec-tools, 2.0.27) ++AC_INIT(kexec-tools, 2.0.27.git) + AC_CONFIG_AUX_DIR(./config) + AC_CONFIG_HEADERS([include/config.h]) + AC_LANG(C) +-- +2.41.0 + diff --git a/0002-build-fix-tarball-creation.patch b/0002-build-fix-tarball-creation.patch new file mode 100644 index 0000000..13837d3 --- /dev/null +++ b/0002-build-fix-tarball-creation.patch @@ -0,0 +1,43 @@ +From c3f35ff06e54daf452ac49a4381cf2643c934866 Mon Sep 17 00:00:00 2001 +From: Leah Neukirchen +Date: Mon, 28 Aug 2023 11:58:15 +0200 +Subject: [PATCH 2/4] build: fix tarball creation + +The fix in 41b77edac did not work, bsdtar still complains about +"hardlink pointing to itself". + +Simplify the code instead: since the staging directory contains +exactly the files we want, just package it as a whole. + +Signed-off-by: Leah Neukirchen +Signed-off-by: Simon Horman +--- + Makefile.in | 5 +---- + 1 file changed, 1 insertion(+), 4 deletions(-) + +diff --git a/Makefile.in b/Makefile.in +index 09bbd5c..3cad22a 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -179,8 +179,6 @@ GENERATED_SRCS:= $(SPEC) + TARBALL=$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar + TARBALL.gz=$(TARBALL).gz + SRCS:= $(dist) +-PSRCS:=$(foreach s, $(SRCS), $(PACKAGE_NAME)-$(PACKAGE_VERSION)/$(s)) +-PGSRCS:=$(foreach s, $(GENERATED_SRCS), $(PACKAGE_NAME)-$(PACKAGE_VERSION)/$(s)) + + MAN_PAGES:=$(KEXEC_MANPAGE) $(VMCORE_DMESG_MANPAGE) + BINARIES_i386:=$(KEXEC_TEST) +@@ -223,8 +221,7 @@ $(TARBALL): $(SRCS) $(GENERATED_SRCS) + $(MKDIR) $(PACKAGE_NAME)-$(PACKAGE_VERSION) + $(TAR) -c $(SRCS) $(GENERATED_SRCS) | \ + $(TAR) -C $(PACKAGE_NAME)-$(PACKAGE_VERSION) -x +- $(TAR) -cf $@ $(PSRCS) +- $(TAR) -rf $@ $(PGSRCS) ++ $(TAR) -cf $@ $(PACKAGE_NAME)-$(PACKAGE_VERSION) + $(RM) -rf $(PACKAGE_NAME)-$(PACKAGE_VERSION) + + $(TARBALL.gz): $(TARBALL) +-- +2.41.0 + diff --git a/0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch b/0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch new file mode 100644 index 0000000..86c8369 --- /dev/null +++ b/0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch @@ -0,0 +1,134 @@ +From 8f08e3b51f25f585dc62f8e7aadc6095e06417cc Mon Sep 17 00:00:00 2001 +From: Dave Young +Date: Thu, 14 Sep 2023 16:49:59 +0800 +Subject: [PATCH 3/4] zboot: enable arm64 kexec_load for zboot image + +kexec_file_load support of zboot kernel image decompressed the vmlinuz, +so in kexec_load code just load the kernel with reading the decompressed +kernel fd into a new buffer and use it directly. + +Signed-off-by: Dave Young +Tested-by: Baoquan He +Reviewed-by: Pingfan Liu +Signed-off-by: Simon Horman +--- + include/kexec-pe-zboot.h | 3 ++- + kexec/arch/arm64/kexec-vmlinuz-arm64.c | 26 +++++++++++++++++++++++--- + kexec/kexec-pe-zboot.c | 4 +++- + kexec/kexec.c | 2 +- + kexec/kexec.h | 1 + + 5 files changed, 30 insertions(+), 6 deletions(-) + +diff --git a/include/kexec-pe-zboot.h b/include/kexec-pe-zboot.h +index e2e0448..374916c 100644 +--- a/include/kexec-pe-zboot.h ++++ b/include/kexec-pe-zboot.h +@@ -11,5 +11,6 @@ struct linux_pe_zboot_header { + uint32_t compress_type; + }; + +-int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd); ++int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd, ++ off_t *kernel_size); + #endif +diff --git a/kexec/arch/arm64/kexec-vmlinuz-arm64.c b/kexec/arch/arm64/kexec-vmlinuz-arm64.c +index c0ee47c..e291a34 100644 +--- a/kexec/arch/arm64/kexec-vmlinuz-arm64.c ++++ b/kexec/arch/arm64/kexec-vmlinuz-arm64.c +@@ -34,6 +34,7 @@ + #include "arch/options.h" + + static int kernel_fd = -1; ++static off_t decompressed_size; + + /* Returns: + * -1 : in case of error/invalid format (not a valid PE+compressed ZBOOT format. +@@ -72,7 +73,7 @@ int pez_arm64_probe(const char *kernel_buf, off_t kernel_size) + return -1; + } + +- ret = pez_prepare(buf, buf_sz, &kernel_fd); ++ ret = pez_prepare(buf, buf_sz, &kernel_fd, &decompressed_size); + + if (!ret) { + /* validate the arm64 specific header */ +@@ -98,8 +99,27 @@ bad_header: + int pez_arm64_load(int argc, char **argv, const char *buf, off_t len, + struct kexec_info *info) + { +- info->kernel_fd = kernel_fd; +- return image_arm64_load(argc, argv, buf, len, info); ++ if (kernel_fd > 0 && decompressed_size > 0) { ++ char *kbuf; ++ off_t nread; ++ int fd; ++ ++ info->kernel_fd = kernel_fd; ++ fd = dup(kernel_fd); ++ if (fd < 0) { ++ dbgprintf("%s: dup fd failed.\n", __func__); ++ return -1; ++ } ++ kbuf = slurp_fd(fd, NULL, decompressed_size, &nread); ++ if (!kbuf || nread != decompressed_size) { ++ dbgprintf("%s: slurp_fd failed.\n", __func__); ++ return -1; ++ } ++ return image_arm64_load(argc, argv, kbuf, decompressed_size, info); ++ } ++ ++ dbgprintf("%s: wrong kernel file descriptor.\n", __func__); ++ return -1; + } + + void pez_arm64_usage(void) +diff --git a/kexec/kexec-pe-zboot.c b/kexec/kexec-pe-zboot.c +index 2f2e052..3abd17d 100644 +--- a/kexec/kexec-pe-zboot.c ++++ b/kexec/kexec-pe-zboot.c +@@ -37,7 +37,8 @@ + * + * crude_buf: the content, which is read from the kernel file without any processing + */ +-int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd) ++int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd, ++ off_t *kernel_size) + { + int ret = -1; + int fd = 0; +@@ -110,6 +111,7 @@ int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd) + goto fail_bad_header; + } + ++ *kernel_size = decompressed_size; + dbgprintf("%s: done\n", __func__); + + ret = 0; +diff --git a/kexec/kexec.c b/kexec/kexec.c +index c3b182e..1edbd34 100644 +--- a/kexec/kexec.c ++++ b/kexec/kexec.c +@@ -489,7 +489,7 @@ static int add_backup_segments(struct kexec_info *info, + return 0; + } + +-static char *slurp_fd(int fd, const char *filename, off_t size, off_t *nread) ++char *slurp_fd(int fd, const char *filename, off_t size, off_t *nread) + { + char *buf; + off_t progress; +diff --git a/kexec/kexec.h b/kexec/kexec.h +index ed3b499..0933389 100644 +--- a/kexec/kexec.h ++++ b/kexec/kexec.h +@@ -267,6 +267,7 @@ extern void die(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); + extern void *xmalloc(size_t size); + extern void *xrealloc(void *ptr, size_t size); ++extern char *slurp_fd(int fd, const char *filename, off_t size, off_t *nread); + extern char *slurp_file(const char *filename, off_t *r_size); + extern char *slurp_file_mmap(const char *filename, off_t *r_size); + extern char *slurp_file_len(const char *filename, off_t size, off_t *nread); +-- +2.41.0 + diff --git a/0004-zboot-add-loongarch-kexec_load-support.patch b/0004-zboot-add-loongarch-kexec_load-support.patch new file mode 100644 index 0000000..7a04237 --- /dev/null +++ b/0004-zboot-add-loongarch-kexec_load-support.patch @@ -0,0 +1,171 @@ +From 2495ccfc52069ecec46031587c94b03ae66ed5d2 Mon Sep 17 00:00:00 2001 +From: Dave Young +Date: Thu, 14 Sep 2023 16:50:00 +0800 +Subject: [PATCH 4/4] zboot: add loongarch kexec_load support + +Copy arm64 code and change for loongarch so that the kexec -c can load +a zboot image. +Note: probe zboot image first otherwise the pei-loongarch file type will +be used. + +Signed-off-by: Dave Young +Signed-off-by: Simon Horman +--- + kexec/arch/loongarch/Makefile | 1 + + kexec/arch/loongarch/image-header.h | 1 + + kexec/arch/loongarch/kexec-loongarch.c | 1 + + kexec/arch/loongarch/kexec-loongarch.h | 4 + + kexec/arch/loongarch/kexec-pez-loongarch.c | 90 ++++++++++++++++++++++ + 5 files changed, 97 insertions(+) + create mode 100644 kexec/arch/loongarch/kexec-pez-loongarch.c + +diff --git a/kexec/arch/loongarch/Makefile b/kexec/arch/loongarch/Makefile +index 3b33b96..cee7e56 100644 +--- a/kexec/arch/loongarch/Makefile ++++ b/kexec/arch/loongarch/Makefile +@@ -6,6 +6,7 @@ loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-elf-loongarch.c + loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-pei-loongarch.c + loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-elf-rel-loongarch.c + loongarch_KEXEC_SRCS += kexec/arch/loongarch/crashdump-loongarch.c ++loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-pez-loongarch.c + + loongarch_MEM_REGIONS = kexec/mem_regions.c + +diff --git a/kexec/arch/loongarch/image-header.h b/kexec/arch/loongarch/image-header.h +index 3b75765..223d81f 100644 +--- a/kexec/arch/loongarch/image-header.h ++++ b/kexec/arch/loongarch/image-header.h +@@ -33,6 +33,7 @@ struct loongarch_image_header { + }; + + static const uint8_t loongarch_image_pe_sig[2] = {'M', 'Z'}; ++static const uint8_t loongarch_pe_machtype[6] = {'P','E', 0x0, 0x0, 0x64, 0x62}; + + /** + * loongarch_header_check_pe_sig - Helper to check the loongarch image header. +diff --git a/kexec/arch/loongarch/kexec-loongarch.c b/kexec/arch/loongarch/kexec-loongarch.c +index f47c998..62ff8fd 100644 +--- a/kexec/arch/loongarch/kexec-loongarch.c ++++ b/kexec/arch/loongarch/kexec-loongarch.c +@@ -165,6 +165,7 @@ int get_memory_ranges(struct memory_range **range, int *ranges, + + struct file_type file_type[] = { + {"elf-loongarch", elf_loongarch_probe, elf_loongarch_load, elf_loongarch_usage}, ++ {"pez-loongarch", pez_loongarch_probe, pez_loongarch_load, pez_loongarch_usage}, + {"pei-loongarch", pei_loongarch_probe, pei_loongarch_load, pei_loongarch_usage}, + }; + int file_types = sizeof(file_type) / sizeof(file_type[0]); +diff --git a/kexec/arch/loongarch/kexec-loongarch.h b/kexec/arch/loongarch/kexec-loongarch.h +index 5120a26..2c7624f 100644 +--- a/kexec/arch/loongarch/kexec-loongarch.h ++++ b/kexec/arch/loongarch/kexec-loongarch.h +@@ -27,6 +27,10 @@ int pei_loongarch_probe(const char *buf, off_t len); + int pei_loongarch_load(int argc, char **argv, const char *buf, off_t len, + struct kexec_info *info); + void pei_loongarch_usage(void); ++int pez_loongarch_probe(const char *kernel_buf, off_t kernel_size); ++int pez_loongarch_load(int argc, char **argv, const char *buf, off_t len, ++ struct kexec_info *info); ++void pez_loongarch_usage(void); + + int loongarch_process_image_header(const struct loongarch_image_header *h); + +diff --git a/kexec/arch/loongarch/kexec-pez-loongarch.c b/kexec/arch/loongarch/kexec-pez-loongarch.c +new file mode 100644 +index 0000000..942a47c +--- /dev/null ++++ b/kexec/arch/loongarch/kexec-pez-loongarch.c +@@ -0,0 +1,90 @@ ++/* ++ * LoongArch PE compressed Image (vmlinuz, ZBOOT) support. ++ * Based on arm64 code ++ */ ++ ++#define _GNU_SOURCE ++#include ++#include ++#include ++#include "kexec.h" ++#include "kexec-loongarch.h" ++#include ++#include "arch/options.h" ++ ++static int kernel_fd = -1; ++static off_t decompressed_size; ++ ++/* Returns: ++ * -1 : in case of error/invalid format (not a valid PE+compressed ZBOOT format. ++ */ ++int pez_loongarch_probe(const char *kernel_buf, off_t kernel_size) ++{ ++ int ret = -1; ++ const struct loongarch_image_header *h; ++ char *buf; ++ off_t buf_sz; ++ ++ buf = (char *)kernel_buf; ++ buf_sz = kernel_size; ++ if (!buf) ++ return -1; ++ h = (const struct loongarch_image_header *)buf; ++ ++ dbgprintf("%s: PROBE.\n", __func__); ++ if (buf_sz < sizeof(struct loongarch_image_header)) { ++ dbgprintf("%s: Not large enough to be a PE image.\n", __func__); ++ return -1; ++ } ++ if (!loongarch_header_check_pe_sig(h)) { ++ dbgprintf("%s: Not an PE image.\n", __func__); ++ return -1; ++ } ++ ++ if (buf_sz < sizeof(struct loongarch_image_header) + h->pe_header) { ++ dbgprintf("%s: PE image offset larger than image.\n", __func__); ++ return -1; ++ } ++ ++ if (memcmp(&buf[h->pe_header], ++ loongarch_pe_machtype, sizeof(loongarch_pe_machtype))) { ++ dbgprintf("%s: PE header doesn't match machine type.\n", __func__); ++ return -1; ++ } ++ ++ ret = pez_prepare(buf, buf_sz, &kernel_fd, &decompressed_size); ++ ++ /* Fixme: add sanity check of the decompressed kernel before return */ ++ return ret; ++} ++ ++int pez_loongarch_load(int argc, char **argv, const char *buf, off_t len, ++ struct kexec_info *info) ++{ ++ if (kernel_fd > 0 && decompressed_size > 0) { ++ char *kbuf; ++ off_t nread; ++ ++ info->kernel_fd = kernel_fd; ++ /* ++ * slurp_fd will close kernel_fd, but it is safe here ++ * due to no kexec_file_load support. ++ */ ++ kbuf = slurp_fd(kernel_fd, NULL, decompressed_size, &nread); ++ if (!kbuf || nread != decompressed_size) { ++ dbgprintf("%s: slurp_fd failed.\n", __func__); ++ return -1; ++ } ++ return pei_loongarch_load(argc, argv, kbuf, decompressed_size, info); ++ } ++ ++ dbgprintf("%s: wrong kernel file descriptor.\n", __func__); ++ return -1; ++} ++ ++void pez_loongarch_usage(void) ++{ ++ printf( ++" An LoongArch vmlinuz, PE image of a compressed, little endian.\n" ++" kernel, built with ZBOOT enabled.\n\n"); ++} +-- +2.41.0 + diff --git a/README.packit b/README.packit index 159f693..daffcaa 100644 --- a/README.packit +++ b/README.packit @@ -1,3 +1,3 @@ This repository is maintained by packit. https://packit.dev/ -The file was generated using packit 0.79.0. +The file was generated using packit 0.80.0. diff --git a/kexec-tools.spec b/kexec-tools.spec index e51d496..67a6da6 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -106,6 +106,18 @@ Requires: systemd-udev%{?_isa} # Patches 601 onward are generic patches # Patch601: kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch +# kexec-tools 2.0.27.git +# Author: Simon Horman +Patch602: 0001-kexec-tools-2.0.27.git.patch +# build: fix tarball creation +# Author: Leah Neukirchen +Patch603: 0002-build-fix-tarball-creation.patch +# zboot: enable arm64 kexec_load for zboot image +# Author: Dave Young +Patch604: 0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch +# zboot: add loongarch kexec_load support +# Author: Dave Young +Patch605: 0004-zboot-add-loongarch-kexec_load-support.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -360,6 +372,9 @@ fi %endif %changelog +* Tue Oct 10 2023 Coiby Xu - 2.0.27-1 +- kexec-tools 2.0.27 (Simon Horman) + * Thu Aug 31 2023 Coiby Xu - 2.0.27-1 - kexec-tools 2.0.27 (Simon Horman) From 5058cef90c2e24ff3a17a9c5560e16363e3281f5 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 13 Oct 2023 11:00:07 +0800 Subject: [PATCH 391/454] Release 2.0.27-2 This release fixes https://datawarehouse.cki-project.org/kcidb/tests/9435999. Signed-off-by: Coiby Xu --- kexec-tools.spec | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 67a6da6..d5740ef 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.27 -Release: 1%{?dist} +Release: 2%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -134,6 +134,10 @@ tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} %patch601 -p1 +%patch602 -p1 +%patch603 -p1 +%patch604 -p1 +%patch605 -p1 %ifarch ppc %define archdef ARCH=ppc @@ -372,6 +376,9 @@ fi %endif %changelog +* Fri Oct 13 2023 Coiby Xu - 2.0.27-2 +- update to latest upstream kexec-tools + * Tue Oct 10 2023 Coiby Xu - 2.0.27-1 - kexec-tools 2.0.27 (Simon Horman) From 0ffce0ef4ef3414e9b44614de3281fa0fb42ca05 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 13 Oct 2023 17:49:56 +0800 Subject: [PATCH 392/454] Only try to reset crashkernel when kdump.service is enabled Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2243068 Currently, when kexec-tools is installed, the kernel will automatically have the crashkernel parameter set up. In the case where users only want the kexec reboot feature, this is not what users want as a 1G-RAM system will lose 192M memory. Considering Fedora's systemd preset policy has kdump.service disabled and RHEL' has kdump.service enabled, this patch makes kexec-tools only reset crashkernel when kdump.service is enabled. Reported-by: Chris Murphy Cc: Philipp Rudo Cc: Adam Williamson Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdumpctl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kdumpctl b/kdumpctl index b6d5994..01433e2 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1649,6 +1649,10 @@ reset_crashkernel_for_installed_kernel() _update_crashkernel "$_installed_kernel" } +_should_reset_crashkernel() { + [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]] && systemctl is-enabled kdump &> /dev/null +} + main() { # Determine if the dump mode is kdump or fadump @@ -1715,12 +1719,12 @@ main() reset_crashkernel "$@" ;; _reset-crashkernel-after-update) - if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then + if _should_reset_crashkernel; then reset_crashkernel_after_update fi ;; _reset-crashkernel-for-installed_kernel) - if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then + if _should_reset_crashkernel; then reset_crashkernel_for_installed_kernel "$2" fi ;; From c9ac933cc20600b3d5792fe14226b54bcbc029e6 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 17 Oct 2023 13:54:48 +0800 Subject: [PATCH 393/454] Release 2.0.27-3 Signed-off-by: Coiby Xu --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index d5740ef..74422ee 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.27 -Release: 2%{?dist} +Release: 3%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -376,6 +376,9 @@ fi %endif %changelog +* Tue Oct 17 2023 Coiby Xu - 2.0.27-3 +- Only try to reset crashkernel when kdump.service is enabled + * Fri Oct 13 2023 Coiby Xu - 2.0.27-2 - update to latest upstream kexec-tools From 3d253ab81134d9f68d230aeeceb3158026b597aa Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 10 Oct 2023 14:31:36 +0800 Subject: [PATCH 394/454] Allow _crashkernel_add to address larger memory ranges Currently _crashkernel_add can't deal with larger memory ranges like terabyte. For example, '_crashkernel_add "128G-1T:4G" "0"' actually returns empty result. This patch allows _crashkernel_add to address terabyte, petabyte and exabyte memory ranges. Fixes: 64f2827a ("kdump-lib: Harden _crashkernel_add") Signed-off-by: Coiby Xu Acked-by: Baoquan He --- kdump-lib.sh | 16 ++++++++++++++-- spec/kdump-lib_spec.sh | 8 +++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index ae39c23..9c1d9e1 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -862,7 +862,7 @@ has_aarch64_smmu() ls /sys/devices/platform/arm-smmu-* 1> /dev/null 2>&1 } -is_memsize() { [[ "$1" =~ ^[+-]?[0-9]+[KkMmGg]?$ ]]; } +is_memsize() { [[ "$1" =~ ^[+-]?[0-9]+[KkMmGgTtPbEe]?$ ]]; } # range defined for crashkernel parameter # i.e. -[] @@ -893,6 +893,18 @@ to_bytes() _s=${_s::-1} _s="$((_s * 1024 * 1024 * 1024))" ;; + T|t) + _s=${_s::-1} + _s="$((_s * 1024 * 1024 * 1024 * 1024))" + ;; + P|p) + _s=${_s::-1} + _s="$((_s * 1024 * 1024 * 1024 * 1024 * 1024))" + ;; + E|e) + _s=${_s::-1} + _s="$((_s * 1024 * 1024 * 1024 * 1024 * 1024 * 1024))" + ;; *) ;; esac @@ -901,7 +913,7 @@ to_bytes() memsize_add() { - local -a units=("" "K" "M" "G") + local -a units=("" "K" "M" "G" "T" "P" "E") local i a b a=$(to_bytes "$1") || return 1 diff --git a/spec/kdump-lib_spec.sh b/spec/kdump-lib_spec.sh index 814f961..f13372c 100644 --- a/spec/kdump-lib_spec.sh +++ b/spec/kdump-lib_spec.sh @@ -52,14 +52,20 @@ Describe 'kdump-lib' Context "For valid input values" Parameters "1G-4G:256M,4G-64G:320M,64G-:576M" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M" + "1G-4G:256M" "100" "1G-4G:268435556" # avoids any rounding when size % 1024 != 0 "1G-4G:256M,4G-64G:320M,64G-:576M@4G" "100M" "1G-4G:356M,4G-64G:420M,64G-:676M@4G" "1G-4G:1G,4G-64G:2G,64G-:3G@4G" "100M" "1G-4G:1124M,4G-64G:2148M,64G-:3172M@4G" "1G-4G:10000K,4G-64G:20000K,64G-:40000K@4G" "100M" "1G-4G:112400K,4G-64G:122400K,64G-:142400K@4G" "1,high" "1" "2,high" "1K,low" "1" "1025,low" + "128G-1T:4G" "0" "128G-1T:4G" + "10T-100T:1T" "0" "10T-100T:1T" + "128G-1T:4G" "0M" "128G-1T:4G" + "128G-1P:4G" "0M" "128G-1P:4G" + "128G-1E:4G" "0M" "128G-1E:4G" "1M@1G" "1k" "1025K@1G" "500M@1G" "-100m" "400M@1G" - "1099511627776" "0" "1024G" + "1099511627776" "0" "1T" End It "should add delta to every value after ':'" When call _crashkernel_add "$1" "$2" From 4841bc6a6dfe4d09640322f6703f60dbfe9f6f19 Mon Sep 17 00:00:00 2001 From: Baoquan He Date: Thu, 21 Sep 2023 18:01:02 +0800 Subject: [PATCH 395/454] kdump-lib.sh: add extra 64M to default crashkernel if sme/sev is active It's reported that kdump kernel failed to boot and can't dump vmcore when crashkernel=192M and SME/SEV is active. This is because swiotlb will be enabled and reserves 64M memory by default on system with SME/SEV enabled. Then kdump kernel will be out of memory after taking 64M away for swiotlb init. So here add extra 64M memory to default crashkernel value so that kdump kernel can function well as before. When doing that, search journalctl for the "Memory Encryption Features active: AMD" to check if SME or SEV is active. This line of log is printed out in kernel function as below and the type SME is mutual exclusive with type SEV. ***: arch/x86/mm/mem_encrypt.c:print_mem_encrypt_feature_info() Note: 1) The conditional check is relying on journalctl log because I didn't find available system interface to check if SEV is active. Even though we can check if SME is active via /proc/cpuinfo. For consistency, I take the same check for both SME and SEV by searching journalctl. 2) The conditional check is relying on journalctl log, means it won't work for crashkernel setting in anoconda because the installation kernel doesn't have the SME/SEV setting. So customer need manually run 'kdumpctl reset-crashkernel' to reset crashkernel to add the extra 64M after OS installation. 3) We need watch the line of log printing in print_mem_encrypt_feature_info() in kernel just in case people may change it in the future. Signed-off-by: Baoquan He Reviewed-by: Philipp Rudo --- kdump-lib.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kdump-lib.sh b/kdump-lib.sh index 9c1d9e1..79714f9 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -38,6 +38,11 @@ is_aws_aarch64() [[ "$(lscpu | grep "BIOS Model name")" =~ "AWS Graviton" ]] } +is_sme_or_sev_active() +{ + journalctl -q --dmesg --grep "^Memory Encryption Features active: AMD (SME|SEV)$" >/dev/null 2>&1 +} + is_squash_available() { local _version kmodule @@ -1001,6 +1006,7 @@ _crashkernel_add() kdump_get_arch_recommend_crashkernel() { local _arch _ck_cmdline _dump_mode + local _delta=0 if [[ -z "$1" ]]; then if is_fadump_capable; then @@ -1016,9 +1022,9 @@ kdump_get_arch_recommend_crashkernel() if [[ $_arch == "x86_64" ]] || [[ $_arch == "s390x" ]]; then _ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M" + is_sme_or_sev_active && ((_delta += 64)) elif [[ $_arch == "aarch64" ]]; then local _running_kernel - local _delta=0 # Base line for 4K variant kernel. The formula is based on x86 plus extra = 64M _ck_cmdline="1G-4G:256M,4G-64G:320M,64G-:576M" @@ -1042,7 +1048,6 @@ kdump_get_arch_recommend_crashkernel() #4k kernel, mlx5 consumes extra 124M memory, and choose 150M has_mlx5 && ((_delta += 150)) fi - _ck_cmdline=$(_crashkernel_add "$_ck_cmdline" "${_delta}M") elif [[ $_arch == "ppc64le" ]]; then if [[ $_dump_mode == "fadump" ]]; then _ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" @@ -1051,7 +1056,7 @@ kdump_get_arch_recommend_crashkernel() fi fi - echo -n "$_ck_cmdline" + echo -n "$(_crashkernel_add "$_ck_cmdline" "${_delta}M")" } # return recommended size based on current system RAM size From cb761c7224fc09c08731a8535eb4b44db010355c Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 8 Nov 2023 11:28:28 +0800 Subject: [PATCH 396/454] Release 2.0.27-4 Signed-off-by: Coiby Xu --- ...exclusion-of-slab-pages-on-Linux-6.2.patch | 81 ------------------- kexec-tools.spec | 11 ++- sources | 1 + 3 files changed, 8 insertions(+), 85 deletions(-) delete mode 100644 kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch diff --git a/kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch b/kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch deleted file mode 100644 index 5d91bc2..0000000 --- a/kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 5f17bdd2128998a3eeeb4521d136a192222fadb6 Mon Sep 17 00:00:00 2001 -From: Kazuhito Hagio -Date: Wed, 21 Dec 2022 11:06:39 +0900 -Subject: [PATCH] [PATCH] Fix wrong exclusion of slab pages on Linux 6.2-rc1 - -* Required for kernel 6.2 - -Kernel commit 130d4df57390 ("mm/sl[au]b: rearrange struct slab fields to -allow larger rcu_head"), which is contained in Linux 6.2-rc1 and later, -made the offset of slab.slabs equal to page.mapping's one. As a result, -"makedumpfile -d 8", which should exclude user data, excludes some slab -pages wrongly because isAnon() returns true when slab.slabs is an odd -number. With such dumpfiles, crash can fail to start session with an -error like this: - - # crash vmlinux dumpfile - ... - crash: page excluded: kernel virtual address: ffff8fa047ac2fe8 type: "xa_node shift" - -Make isAnon() check that the page is not slab to fix this. - -Signed-off-by: Kazuhito Hagio ---- - makedumpfile.c | 6 +++--- - makedumpfile.h | 9 +++------ - 2 files changed, 6 insertions(+), 9 deletions(-) - -diff --git a/makedumpfile-1.7.2/makedumpfile.c b/makedumpfile-1.7.2/makedumpfile.c -index ff821eb..f403683 100644 ---- a/makedumpfile-1.7.2/makedumpfile.c -+++ b/makedumpfile-1.7.2/makedumpfile.c -@@ -6502,7 +6502,7 @@ __exclude_unnecessary_pages(unsigned long mem_map, - */ - else if ((info->dump_level & DL_EXCLUDE_CACHE) - && is_cache_page(flags) -- && !isPrivate(flags) && !isAnon(mapping)) { -+ && !isPrivate(flags) && !isAnon(mapping, flags)) { - pfn_counter = &pfn_cache; - } - /* -@@ -6510,7 +6510,7 @@ __exclude_unnecessary_pages(unsigned long mem_map, - */ - else if ((info->dump_level & DL_EXCLUDE_CACHE_PRI) - && is_cache_page(flags) -- && !isAnon(mapping)) { -+ && !isAnon(mapping, flags)) { - if (isPrivate(flags)) - pfn_counter = &pfn_cache_private; - else -@@ -6522,7 +6522,7 @@ __exclude_unnecessary_pages(unsigned long mem_map, - * - hugetlbfs pages - */ - else if ((info->dump_level & DL_EXCLUDE_USER_DATA) -- && (isAnon(mapping) || isHugetlb(compound_dtor))) { -+ && (isAnon(mapping, flags) || isHugetlb(compound_dtor))) { - pfn_counter = &pfn_user; - } - /* -diff --git a/makedumpfile-1.7.2/makedumpfile.h b/makedumpfile-1.7.2/makedumpfile.h -index 70a1a91..21dec7d 100644 ---- a/makedumpfile-1.7.2/makedumpfile.h -+++ b/makedumpfile-1.7.2/makedumpfile.h -@@ -161,12 +161,9 @@ test_bit(int nr, unsigned long addr) - #define isSwapBacked(flags) test_bit(NUMBER(PG_swapbacked), flags) - #define isHWPOISON(flags) (test_bit(NUMBER(PG_hwpoison), flags) \ - && (NUMBER(PG_hwpoison) != NOT_FOUND_NUMBER)) -- --static inline int --isAnon(unsigned long mapping) --{ -- return ((unsigned long)mapping & PAGE_MAPPING_ANON) != 0; --} -+#define isSlab(flags) test_bit(NUMBER(PG_slab), flags) -+#define isAnon(mapping, flags) (((unsigned long)mapping & PAGE_MAPPING_ANON) != 0 \ -+ && !isSlab(flags)) - - #define PTOB(X) (((unsigned long long)(X)) << PAGESHIFT()) - #define BTOP(X) (((unsigned long long)(X)) >> PAGESHIFT()) --- -2.39.0 - diff --git a/kexec-tools.spec b/kexec-tools.spec index 74422ee..cb1a408 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,11 +1,11 @@ %global eppic_ver e8844d3793471163ae4a56d8f95897be9e5bd554 %global eppic_shortver %(c=%{eppic_ver}; echo ${c:0:7}) -%global mkdf_ver 1.7.2 +%global mkdf_ver 1.7.4 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools Version: 2.0.27 -Release: 3%{?dist} +Release: 4%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -105,7 +105,6 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # -Patch601: kexec-tools-2.0.26-makedumpfile-Fix-wrong-exclusion-of-slab-pages-on-Linux-6.2.patch # kexec-tools 2.0.27.git # Author: Simon Horman Patch602: 0001-kexec-tools-2.0.27.git.patch @@ -133,7 +132,6 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} -%patch601 -p1 %patch602 -p1 %patch603 -p1 %patch604 -p1 @@ -376,6 +374,11 @@ fi %endif %changelog +* Wed Nov 08 2023 Coiby Xu - 2.0.27-4 +- update to makedumpfile-1.7.4 +- kdump-lib.sh: add extra 64M to default crashkernel if sme/sev is active +- Allow _crashkernel_add to address larger memory ranges + * Tue Oct 17 2023 Coiby Xu - 2.0.27-3 - Only try to reset crashkernel when kdump.service is enabled diff --git a/sources b/sources index 54a591c..fd41a48 100644 --- a/sources +++ b/sources @@ -1,3 +1,4 @@ SHA512 (kexec-tools-2.0.27.tar.xz) = 30b5ef7c2075dfd11fd1c3c33abe6b60673400257668d60145be08a2472356c7191a0810095da0fa32e327b9806a7578c73129ac0550d26c28ea6571c88c7b3c SHA512 (makedumpfile-1.7.2.tar.gz) = 324e303dd5f507703f66e2bd5dc9d24f9f50ba797be70c05702008ba77078f61ffcc884796ddf9ab737de1d124c3a9d881ab5ce4f3f459690ec00055af25ea9e SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 +SHA512 (makedumpfile-1.7.4.tar.gz) = 6c3455b711bd4e120173ee07fcc5ff708ae6d34eaee0f4c135eca7ee0e0475b4d391429c23cf68e848b156ee3edeab956e693a390d67ccc634c43224c7129a96 From 741861164e24247e995d47a8284b7493cb73b769 Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Mon, 30 Oct 2023 14:51:59 +0800 Subject: [PATCH 397/454] kdumpctl: Only returns immediately after an error occurs in check_*_modified Currently is_system_modified will return immediately when check_*_modified return a non-zero value, and the remaining checks will not be executed. For example, if there is a fs-related error exists, and someone changes the kdump.conf, check_files_modified will return 1 and is_system_modified will return 1 immediately. This will cause kdumpctl to skip check_fs/drivers_modified, kdump.service will rebuild the initrd and start successfully, however, any errors should prevent kdump.service from starting. This patch will cause check_*_modifed to continue running until an error occurs or all execution ends. Signed-off-by: Lichen Liu Acked-by: Tao Liu --- kdumpctl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kdumpctl b/kdumpctl index 01433e2..3da5fff 100755 --- a/kdumpctl +++ b/kdumpctl @@ -605,6 +605,10 @@ check_fs_modified() is_system_modified() { local ret + local CONF_ERROR=2 + local CONF_MODIFY=1 + local CONF_NO_MODIFY=0 + local conf_status=$CONF_NO_MODIFY [[ -f $TARGET_INITRD ]] || return 1 @@ -617,9 +621,15 @@ is_system_modified() fi fi - check_files_modified || return - check_fs_modified || return - check_drivers_modified + for _func in check_files_modified check_fs_modified check_drivers_modified; do + $_func + ret=$? + # return immediately if an error occurred. + [[ $ret -eq "$CONF_ERROR" ]] && return "$ret" + [[ $ret -eq "$CONF_MODIFY" ]] && { conf_status="$CONF_MODIFY"; } + done + + return $conf_status } # need_initrd_rebuild - check whether the initrd needs to be rebuild From 0177e24832e8d3e5ea2e033c55b616bdd0cf3e9b Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 7 Nov 2023 08:28:59 +0800 Subject: [PATCH 398/454] Use the same /etc/resolve.conf in kdump initrd if it's managed manually Resolves: https://issues.redhat.com/browse/RHEL-11897 Some users may choose to manage /etc/resolve.conf manually [1] by setting dns=none or use a symbolic link resolve.conf [2]. In this case, network dumping will not work because DNS resolution fails. Use the same /etc/resolve.conf in kdump initrd to fix this problem. [1] https://bugzilla.gnome.org/show_bug.cgi?id=690404 [2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/manually-configuring-the-etc-resolv-conf-file_configuring-and-managing-networking Fixes: 63c3805c ("Set up kdump network by directly copying NM connection profile to initrd") Reported-by: Curtis Taylor Cc: Jie Li Signed-off-by: Coiby Xu Reviewed-by: Dave Young --- dracut-module-setup.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index ff53d08..ab6dc4f 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -563,6 +563,33 @@ kdump_collect_netif_usage() { fi } +kdump_install_resolv_conf() { + local _resolv_conf=/etc/resolv.conf _nm_conf_dir=/etc/NetworkManager/conf.d + + # Some users may choose to manage /etc/resolve.conf manually [1] + # by setting dns=none or use a symbolic link resolve.conf [2]. + # So resolve.conf should be installed to kdump initrd as well. To prevent + # NM frome overwritting the user-configured resolve.conf in kdump initrd, + # also set dns=none for NM. + # + # Note: + # 1. When resolv.conf is managed by systemd-resolved.service, it could also be a + # symbolic link. So exclude this case by teling if systemd-resolved is enabled. + # + # 2. It's harmless to blindly copy /etc/resolve.conf to the initrd because + # by default in initramfs this file will be overwritten by + # NetworkManager. If user manages it via a symbolic link, it's still + # preserved because NM won't touch a symbolic link file. + # + # [1] https://bugzilla.gnome.org/show_bug.cgi?id=690404 + # [2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/manually-configuring-the-etc-resolv-conf-file_configuring-and-managing-networking + systemctl -q is-enabled systemd-resolved && return 0 + inst "$_resolv_conf" + if NetworkManager --print-config | grep -qs "^dns=none"; then + echo "[main]\ndns=none" > "$_nm_conf_dir"/90-dns-none.conf + fi +} + # Setup dracut to bring up network interface that enable # initramfs accessing giving destination kdump_install_net() { @@ -575,6 +602,7 @@ kdump_install_net() { kdump_setup_znet kdump_install_nm_netif_allowlist "$_netifs" kdump_install_nic_driver "$_netifs" + kdump_install_resolv_conf fi } From bc31f6dd0fc5234eb62de884aa7a7a8686630d05 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 16 Nov 2023 10:19:19 +0800 Subject: [PATCH 399/454] Let %post scriptlet always exits with the zero exit status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2247940 Currently, CoreOS image fails to be built. This is because since commit 00c37d8c ("spec: Drop special handling for IA64 machines"), the last command is now servicelog_notify and it fails to run in such invocation environment. Thus the %post scriptlet returns a non-zero exit code which breaks package installation, Running scriptlet: kexec-tools-2.0.27-4.fc40.ppc64le /proc/ is not mounted. This is not a supported mode of operation. Please fix your invocation environment to mount /proc/ and /sys/ properly. Proceeding anyway. Your mileage may vary. servicelog_notify: is not supported on the Unknown platform warning: %post(kexec-tools-2.0.27-4.fc40.ppc64le) scriptlet failed, exit status 1 Error in POSTIN scriptlet in rpm package kexec-tools Quoting [1], > Non-zero exit codes from scriptlets can break installs/upgrades/erases > such that no further actions will be taken for that package in a > transaction (see Ordering), which may for example prevent an old version > of a package from being erased on upgrades, ... > > All scriptlets MUST exit with the zero exit status. Because RPM in its > default configuration does not execute shell scriptlets with the -e > argument to the shell, excluding explicit exit calls (frowned upon with > a non-zero argument!), the exit status of the last command in a > scriptlet determines its exit status... > > Usually the most important bit is to apply this to the last command > executed in a scriptlet, or to add a separate command such as plain “:” > or “exit 0” as the last one in a scriptlet. Following the above suggestion, add a separate command ":" as the last one to the %post scriptlet. [1] https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/ Reported-by: Colin Walters Cc: Dusty Mabe Cc: Philipp Rudo Fixes: 00c37d8c ("spec: Drop special handling for IA64 machines") Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kexec-tools.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/kexec-tools.spec b/kexec-tools.spec index cb1a408..19b0b69 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -271,6 +271,7 @@ touch /etc/kdump.conf servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh 2>/dev/null servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match='refcode="#MIGRATE" and serviceable=0' --type=EVENT --method=pairs_stdin >/dev/null %endif +: %postun From 00d40c448b0368639681d482e86d382d1c65e6d9 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 11 Dec 2023 18:17:57 +0800 Subject: [PATCH 400/454] Release 2.0.27-5 Signed-off-by: Coiby Xu --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 19b0b69..5040a4f 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.27 -Release: 4%{?dist} +Release: 5%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -375,6 +375,9 @@ fi %endif %changelog +* Mon Dec 11 2023 Coiby Xu - 2.0.27-5 +- Let %post scriptlet always exits with the zero exit status + * Wed Nov 08 2023 Coiby Xu - 2.0.27-4 - update to makedumpfile-1.7.4 - kdump-lib.sh: add extra 64M to default crashkernel if sme/sev is active From c752cbb2d393c9ae27475f184e2933ff65be50b1 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 6 Dec 2023 16:15:50 +0800 Subject: [PATCH 401/454] Explain the auto_reset_crashkernel option in more details Resolves: https://issues.redhat.com/browse/RHEL-17451 Explain what factors affect the default crashkernel value and ask users to reset it manually if needed. Cc: Baoquan He Cc: Jie Li Acked-by: Baoquan He Signed-off-by: Coiby Xu --- kdump.conf.5 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kdump.conf.5 b/kdump.conf.5 index 9117aa7..0e6ff21 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -29,7 +29,20 @@ understand how this configuration file affects the behavior of kdump. .B auto_reset_crashkernel .RS determine whether to reset kernel crashkernel parameter to the default value -or not when kexec-tools is updated or a new kernel is installed. +or not when kexec-tools is updated or a new kernel is installed. The default +crashkernel values are different for different architectures and also take the +following factors into consideration, + - AMD Secure Memory Encryption (SME) and Secure Encrypted Virtualization (SEV) + - Mellanox 5th generation network driver + - aarch64 64k kernel + - Firmware-assisted dump (FADump) + +Since the kernel crasherkernel parameter will be only reset when kexec-tools is +updated or a new kernel is installed, you need to call "kdumpctl +reset-crashkernel [--kernel=path_to_kernel]" if you want to use the default +value set after having enabled features like SME/SEV for a specific kernel. And +you should also reboot the system for the new crashkernel value to take effect. +Also see kdumpctl(8). .B raw .RS From 38d9990389d80039964668a4db9cc9c039eac68f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 26 Dec 2023 11:17:29 +0800 Subject: [PATCH 402/454] Use the same /etc/resolve.conf in kdump initrd if it's managed manually Resolves: https://issues.redhat.com/browse/RHEL-11897 Previously fix 0177e248 ("Use the same /etc/resolve.conf in kdump initrd if it's managed manually") is problematic, 1) it generated .conf file unrecognized by NetowrkManager ; 2) this .conf file was installed to current file system instead of to the kdump initrd; 3) this incorrect .conf file prevented the starting of NetworkManager. This patch fixes the above issues and also suppresses a harmless warning when systemd-resolved.service doesn't exist, # systemctl -q is-enabled systemd-resolved Failed to get unit file state for systemd-resolved.service: No such file or directory Fixes: 0177e248 ("Use the same /etc/resolve.conf in kdump initrd if it's managed manually") Reported-by: Jie Li Cc: Dave Young Reviewed-by: Dave Young Signed-off-by: Coiby Xu --- dracut-module-setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index ab6dc4f..1dc88dc 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -583,10 +583,10 @@ kdump_install_resolv_conf() { # # [1] https://bugzilla.gnome.org/show_bug.cgi?id=690404 # [2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/manually-configuring-the-etc-resolv-conf-file_configuring-and-managing-networking - systemctl -q is-enabled systemd-resolved && return 0 + systemctl -q is-enabled systemd-resolved 2> /dev/null && return 0 inst "$_resolv_conf" if NetworkManager --print-config | grep -qs "^dns=none"; then - echo "[main]\ndns=none" > "$_nm_conf_dir"/90-dns-none.conf + printf "[main]\ndns=none\n" > "${initdir}/${_nm_conf_dir}"/90-dns-none.conf fi } From 0d90d580b4ff6e4fb7a09175bd7e6e35abbf6afd Mon Sep 17 00:00:00 2001 From: Steffen Maier Date: Thu, 9 Nov 2023 16:50:39 +0100 Subject: [PATCH 403/454] dracut-module-setup: consolidate s390 network device config (#1937048) This is a preparation for consolidating s390 network device config with https://github.com/dracutdevs/dracut/pull/2534 ("feat(znet): use zdev for consolidated device configuration") https://github.com/steffen-maier/s390utils/pull/1/commits ("znet: migrate to consolidated persistent device config with zdev (#1937046,#1937048))" ("znet: clean up old deprecated persistent device config (#1937046,#1937048)"). With above consolidation, s390-specific low-level configuration information will no longer be in NetworkManager connections (nor ifcfg files), but in the persistent configuration database of chzdev from s390-tools. Since the kdump dracut module here depends on the "znet" dracut module [1] and "znet" will copy all persistent configuration into initrd as of above commit, all s390-specific information would already be in the kdump initrd. [1] 08de71252814 ("Move some dracut module dependencies checks to module-setup.sh"), 7148c0a30dfc ("add s390x netdev setup") However, it is more appropriate and also removes the copy dependency from "znet" to introduce the consolidated zdev mechanism for importing just the required network device config from the current active system configuration. It does not depend on any of the pull requests above. It does not depend on any existing persistent configuration and can replace the old function code. This is similar to dracut block device dependency handling in s390-tools zdev/dracut/95zdev-kdump. The old code only seems to work if there is exactly one s390-specific nmconnection (or ifcfg file). Related commits: b5577c163aff ("Simplify setup_znet by copying connection profile to initrd"), 7d472515688f ("Iterate /sys/bus/ccwgroup/devices to tell if we should set up rd.znet"), 8b08b4f17ba0 ("Set up s390 znet cmdline by "nmcli --get-values""), ce0305d4f95c ("Add a new option 'rd.znet_ifname' in order to use it in udev rules"), 7148c0a30dfc ("add s390x netdev setup"). A bonding or teaming setup would have multiple following network interfaces, each of which would need a low-level config if they're s390 channel-attached network devices. The new code should be able to handle that by iterating the involved network interfaces. Chzdev only exports something if it's a device type it deems itself responsible for. Additional debugging output can be generated with e.g. dracut option "--stdlog 5" (or short -L5). It shows the chzdev export result, the output of chzdev export and import, and an overview of the resulting persistent config within the initrd. On systems, which default to using dracut option "--quiet", you might need an additional "--verbose" to counter "--quiet" so -L5 has effect. Typically combined with "--debug" to get a shell trace from building an initrd (Note: --debug does not increase the log levels). Signed-off-by: Steffen Maier Reviewed-by: Philipp Rudo Reviewed-by: Coiby Xu --- dracut-module-setup.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 1dc88dc..01efdeb 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -26,6 +26,9 @@ check() { if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then return 1 fi + if [[ "$(uname -m)" == "s390x" ]]; then + require_binaries chzdev || return 1 + fi return 0 } @@ -474,6 +477,8 @@ _find_znet_nmconnection() { # # Note part of code is extracted from ccw_init provided by s390utils kdump_setup_znet() { + local _netif + local _tempfile=$(mktemp --tmpdir="$_DRACUT_KDUMP_NM_TMP_DIR" kdump-dracut-zdev.XXXXXX) local _config_file _unique_name _NM_conf_dir local __sed_discard_ignored_files='/\(~\|\.bak\|\.old\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' @@ -481,6 +486,18 @@ kdump_setup_znet() { return fi + for _netif in $1; do + chzdev --export "$_tempfile" --active --by-interface "$_netif" \ + 2>&1 | ddebug + sed -i -e 's/^\[active /\[persistent /' "$_tempfile" + ddebug < "$_tempfile" + chzdev --import "$_tempfile" --persistent --base "/etc=$initdir/etc" \ + --yes --no-root-update --force 2>&1 | ddebug + lszdev --configured --persistent --info --by-interface "$_netif" \ + --base "/etc=$initdir/etc" 2>&1 | ddebug + done + rm -f "$_tempfile" + _NM_conf_dir="/etc/NetworkManager/system-connections" _config_file=$(_find_znet_nmconnection "$initdir/$_NM_conf_dir" "$__sed_discard_ignored_files") @@ -599,7 +616,7 @@ kdump_install_net() { if [[ -n "$_netifs" ]]; then kdump_install_nmconnections apply_nm_initrd_generator_timeouts - kdump_setup_znet + kdump_setup_znet "$_netifs" kdump_install_nm_netif_allowlist "$_netifs" kdump_install_nic_driver "$_netifs" kdump_install_resolv_conf From 73c9eb71e9a1709f86b7683e0c532067900608c8 Mon Sep 17 00:00:00 2001 From: Steffen Maier Date: Thu, 9 Nov 2023 16:50:40 +0100 Subject: [PATCH 404/454] dracut-module-setup: remove old s390 network device config (#1937048) Since the previous commit reworks znet configuration to be based on the active system configuration, there is no dependency on any existing persistent configuration any more. Hence the old code handling systems with exactly one s390-specific nmconnection as persistent configuration can be removed. Migration of the old persistent device configuration mechanism with nmconnections (or ifcfg) to zdev is handled independently in s390utils. [https://github.com/steffen-maier/s390utils/pull/1/commits ("znet: migrate to consolidated persistent device config with zdev (#1937046,#1937048))"] Signed-off-by: Steffen Maier Reviewed-by: Philipp Rudo Reviewed-by: Coiby Xu --- dracut-module-setup.sh | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 01efdeb..e39bc13 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -467,20 +467,10 @@ kdump_setup_vlan() { _save_kdump_netifs "$_parent_netif" } -_find_znet_nmconnection() { - LANG=C grep -s -E -i -l \ - "^s390-subchannels=([0-9]\.[0-9]\.[a-f0-9]+;){0,2}" \ - "$1"/*.nmconnection | LC_ALL=C sed -e "$2" -} - # setup s390 znet -# -# Note part of code is extracted from ccw_init provided by s390utils kdump_setup_znet() { local _netif local _tempfile=$(mktemp --tmpdir="$_DRACUT_KDUMP_NM_TMP_DIR" kdump-dracut-zdev.XXXXXX) - local _config_file _unique_name _NM_conf_dir - local __sed_discard_ignored_files='/\(~\|\.bak\|\.old\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d' if [[ "$(uname -m)" != "s390x" ]]; then return @@ -497,32 +487,6 @@ kdump_setup_znet() { --base "/etc=$initdir/etc" 2>&1 | ddebug done rm -f "$_tempfile" - - _NM_conf_dir="/etc/NetworkManager/system-connections" - - _config_file=$(_find_znet_nmconnection "$initdir/$_NM_conf_dir" "$__sed_discard_ignored_files") - if [[ -n "$_config_file" ]]; then - ddebug "$_config_file has already contained the znet config" - return - fi - - _config_file=$(LANG=C grep -s -E -i -l \ - "^[[:space:]]*SUBCHANNELS=['\"]?([0-9]\.[0-9]\.[a-f0-9]+,){0,2}" \ - /etc/sysconfig/network-scripts/ifcfg-* \ - | LC_ALL=C sed -e "$__sed_discard_ignored_files") - - if [[ -z "$_config_file" ]]; then - _config_file=$(_find_znet_nmconnection "$_NM_conf_dir" "$__sed_discard_ignored_files") - fi - - if [[ -n "$_config_file" ]]; then - _unique_name=$(cat /proc/sys/kernel/random/uuid) - nmcli connection clone --temporary "$_config_file" "$_unique_name" &> >(ddebug) - nmcli connection modify --temporary "$_unique_name" connection.autoconnect false - inst "/run/NetworkManager/system-connections/${_unique_name}.nmconnection" "${_NM_conf_dir}/${_unique_name}.nmconnection" - nmcli connection del "$_unique_name" &> >(ddebug) - fi - } kdump_get_remote_ip() { From d78cab14bce98f4c6dfac295fe9e97b21c14e0c3 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 17 Jan 2024 13:46:51 +0800 Subject: [PATCH 405/454] 2.0.28 upstream release Upstream tag: v2.0.28 Upstream commit: adef8a8e Signed-off-by: Coiby Xu --- 0001-kexec-tools-2.0.27.git.patch | 30 --- 0002-build-fix-tarball-creation.patch | 43 ----- ...ble-arm64-kexec_load-for-zboot-image.patch | 134 -------------- ...oot-add-loongarch-kexec_load-support.patch | 171 ------------------ README.packit | 2 +- kexec-tools.spec | 25 +-- sources | 3 +- 7 files changed, 9 insertions(+), 399 deletions(-) delete mode 100644 0001-kexec-tools-2.0.27.git.patch delete mode 100644 0002-build-fix-tarball-creation.patch delete mode 100644 0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch delete mode 100644 0004-zboot-add-loongarch-kexec_load-support.patch diff --git a/0001-kexec-tools-2.0.27.git.patch b/0001-kexec-tools-2.0.27.git.patch deleted file mode 100644 index 3939f62..0000000 --- a/0001-kexec-tools-2.0.27.git.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 056c179cd3c2af0c3bd2762a8a3bfd1340278e9e Mon Sep 17 00:00:00 2001 -From: Simon Horman -Date: Fri, 1 Sep 2023 09:37:24 +0200 -Subject: [PATCH 1/4] kexec-tools 2.0.27.git - -Add .git to version so it doesn't look like a release. -This is just so when people build code from git it can -be identified as such from the version string. - -Signed-off-by: Simon Horman ---- - configure.ac | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/configure.ac b/configure.ac -index 192976c..352eefe 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -4,7 +4,7 @@ dnl - dnl - - dnl ---Required --AC_INIT(kexec-tools, 2.0.27) -+AC_INIT(kexec-tools, 2.0.27.git) - AC_CONFIG_AUX_DIR(./config) - AC_CONFIG_HEADERS([include/config.h]) - AC_LANG(C) --- -2.41.0 - diff --git a/0002-build-fix-tarball-creation.patch b/0002-build-fix-tarball-creation.patch deleted file mode 100644 index 13837d3..0000000 --- a/0002-build-fix-tarball-creation.patch +++ /dev/null @@ -1,43 +0,0 @@ -From c3f35ff06e54daf452ac49a4381cf2643c934866 Mon Sep 17 00:00:00 2001 -From: Leah Neukirchen -Date: Mon, 28 Aug 2023 11:58:15 +0200 -Subject: [PATCH 2/4] build: fix tarball creation - -The fix in 41b77edac did not work, bsdtar still complains about -"hardlink pointing to itself". - -Simplify the code instead: since the staging directory contains -exactly the files we want, just package it as a whole. - -Signed-off-by: Leah Neukirchen -Signed-off-by: Simon Horman ---- - Makefile.in | 5 +---- - 1 file changed, 1 insertion(+), 4 deletions(-) - -diff --git a/Makefile.in b/Makefile.in -index 09bbd5c..3cad22a 100644 ---- a/Makefile.in -+++ b/Makefile.in -@@ -179,8 +179,6 @@ GENERATED_SRCS:= $(SPEC) - TARBALL=$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar - TARBALL.gz=$(TARBALL).gz - SRCS:= $(dist) --PSRCS:=$(foreach s, $(SRCS), $(PACKAGE_NAME)-$(PACKAGE_VERSION)/$(s)) --PGSRCS:=$(foreach s, $(GENERATED_SRCS), $(PACKAGE_NAME)-$(PACKAGE_VERSION)/$(s)) - - MAN_PAGES:=$(KEXEC_MANPAGE) $(VMCORE_DMESG_MANPAGE) - BINARIES_i386:=$(KEXEC_TEST) -@@ -223,8 +221,7 @@ $(TARBALL): $(SRCS) $(GENERATED_SRCS) - $(MKDIR) $(PACKAGE_NAME)-$(PACKAGE_VERSION) - $(TAR) -c $(SRCS) $(GENERATED_SRCS) | \ - $(TAR) -C $(PACKAGE_NAME)-$(PACKAGE_VERSION) -x -- $(TAR) -cf $@ $(PSRCS) -- $(TAR) -rf $@ $(PGSRCS) -+ $(TAR) -cf $@ $(PACKAGE_NAME)-$(PACKAGE_VERSION) - $(RM) -rf $(PACKAGE_NAME)-$(PACKAGE_VERSION) - - $(TARBALL.gz): $(TARBALL) --- -2.41.0 - diff --git a/0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch b/0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch deleted file mode 100644 index 86c8369..0000000 --- a/0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch +++ /dev/null @@ -1,134 +0,0 @@ -From 8f08e3b51f25f585dc62f8e7aadc6095e06417cc Mon Sep 17 00:00:00 2001 -From: Dave Young -Date: Thu, 14 Sep 2023 16:49:59 +0800 -Subject: [PATCH 3/4] zboot: enable arm64 kexec_load for zboot image - -kexec_file_load support of zboot kernel image decompressed the vmlinuz, -so in kexec_load code just load the kernel with reading the decompressed -kernel fd into a new buffer and use it directly. - -Signed-off-by: Dave Young -Tested-by: Baoquan He -Reviewed-by: Pingfan Liu -Signed-off-by: Simon Horman ---- - include/kexec-pe-zboot.h | 3 ++- - kexec/arch/arm64/kexec-vmlinuz-arm64.c | 26 +++++++++++++++++++++++--- - kexec/kexec-pe-zboot.c | 4 +++- - kexec/kexec.c | 2 +- - kexec/kexec.h | 1 + - 5 files changed, 30 insertions(+), 6 deletions(-) - -diff --git a/include/kexec-pe-zboot.h b/include/kexec-pe-zboot.h -index e2e0448..374916c 100644 ---- a/include/kexec-pe-zboot.h -+++ b/include/kexec-pe-zboot.h -@@ -11,5 +11,6 @@ struct linux_pe_zboot_header { - uint32_t compress_type; - }; - --int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd); -+int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd, -+ off_t *kernel_size); - #endif -diff --git a/kexec/arch/arm64/kexec-vmlinuz-arm64.c b/kexec/arch/arm64/kexec-vmlinuz-arm64.c -index c0ee47c..e291a34 100644 ---- a/kexec/arch/arm64/kexec-vmlinuz-arm64.c -+++ b/kexec/arch/arm64/kexec-vmlinuz-arm64.c -@@ -34,6 +34,7 @@ - #include "arch/options.h" - - static int kernel_fd = -1; -+static off_t decompressed_size; - - /* Returns: - * -1 : in case of error/invalid format (not a valid PE+compressed ZBOOT format. -@@ -72,7 +73,7 @@ int pez_arm64_probe(const char *kernel_buf, off_t kernel_size) - return -1; - } - -- ret = pez_prepare(buf, buf_sz, &kernel_fd); -+ ret = pez_prepare(buf, buf_sz, &kernel_fd, &decompressed_size); - - if (!ret) { - /* validate the arm64 specific header */ -@@ -98,8 +99,27 @@ bad_header: - int pez_arm64_load(int argc, char **argv, const char *buf, off_t len, - struct kexec_info *info) - { -- info->kernel_fd = kernel_fd; -- return image_arm64_load(argc, argv, buf, len, info); -+ if (kernel_fd > 0 && decompressed_size > 0) { -+ char *kbuf; -+ off_t nread; -+ int fd; -+ -+ info->kernel_fd = kernel_fd; -+ fd = dup(kernel_fd); -+ if (fd < 0) { -+ dbgprintf("%s: dup fd failed.\n", __func__); -+ return -1; -+ } -+ kbuf = slurp_fd(fd, NULL, decompressed_size, &nread); -+ if (!kbuf || nread != decompressed_size) { -+ dbgprintf("%s: slurp_fd failed.\n", __func__); -+ return -1; -+ } -+ return image_arm64_load(argc, argv, kbuf, decompressed_size, info); -+ } -+ -+ dbgprintf("%s: wrong kernel file descriptor.\n", __func__); -+ return -1; - } - - void pez_arm64_usage(void) -diff --git a/kexec/kexec-pe-zboot.c b/kexec/kexec-pe-zboot.c -index 2f2e052..3abd17d 100644 ---- a/kexec/kexec-pe-zboot.c -+++ b/kexec/kexec-pe-zboot.c -@@ -37,7 +37,8 @@ - * - * crude_buf: the content, which is read from the kernel file without any processing - */ --int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd) -+int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd, -+ off_t *kernel_size) - { - int ret = -1; - int fd = 0; -@@ -110,6 +111,7 @@ int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd) - goto fail_bad_header; - } - -+ *kernel_size = decompressed_size; - dbgprintf("%s: done\n", __func__); - - ret = 0; -diff --git a/kexec/kexec.c b/kexec/kexec.c -index c3b182e..1edbd34 100644 ---- a/kexec/kexec.c -+++ b/kexec/kexec.c -@@ -489,7 +489,7 @@ static int add_backup_segments(struct kexec_info *info, - return 0; - } - --static char *slurp_fd(int fd, const char *filename, off_t size, off_t *nread) -+char *slurp_fd(int fd, const char *filename, off_t size, off_t *nread) - { - char *buf; - off_t progress; -diff --git a/kexec/kexec.h b/kexec/kexec.h -index ed3b499..0933389 100644 ---- a/kexec/kexec.h -+++ b/kexec/kexec.h -@@ -267,6 +267,7 @@ extern void die(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); - extern void *xmalloc(size_t size); - extern void *xrealloc(void *ptr, size_t size); -+extern char *slurp_fd(int fd, const char *filename, off_t size, off_t *nread); - extern char *slurp_file(const char *filename, off_t *r_size); - extern char *slurp_file_mmap(const char *filename, off_t *r_size); - extern char *slurp_file_len(const char *filename, off_t size, off_t *nread); --- -2.41.0 - diff --git a/0004-zboot-add-loongarch-kexec_load-support.patch b/0004-zboot-add-loongarch-kexec_load-support.patch deleted file mode 100644 index 7a04237..0000000 --- a/0004-zboot-add-loongarch-kexec_load-support.patch +++ /dev/null @@ -1,171 +0,0 @@ -From 2495ccfc52069ecec46031587c94b03ae66ed5d2 Mon Sep 17 00:00:00 2001 -From: Dave Young -Date: Thu, 14 Sep 2023 16:50:00 +0800 -Subject: [PATCH 4/4] zboot: add loongarch kexec_load support - -Copy arm64 code and change for loongarch so that the kexec -c can load -a zboot image. -Note: probe zboot image first otherwise the pei-loongarch file type will -be used. - -Signed-off-by: Dave Young -Signed-off-by: Simon Horman ---- - kexec/arch/loongarch/Makefile | 1 + - kexec/arch/loongarch/image-header.h | 1 + - kexec/arch/loongarch/kexec-loongarch.c | 1 + - kexec/arch/loongarch/kexec-loongarch.h | 4 + - kexec/arch/loongarch/kexec-pez-loongarch.c | 90 ++++++++++++++++++++++ - 5 files changed, 97 insertions(+) - create mode 100644 kexec/arch/loongarch/kexec-pez-loongarch.c - -diff --git a/kexec/arch/loongarch/Makefile b/kexec/arch/loongarch/Makefile -index 3b33b96..cee7e56 100644 ---- a/kexec/arch/loongarch/Makefile -+++ b/kexec/arch/loongarch/Makefile -@@ -6,6 +6,7 @@ loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-elf-loongarch.c - loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-pei-loongarch.c - loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-elf-rel-loongarch.c - loongarch_KEXEC_SRCS += kexec/arch/loongarch/crashdump-loongarch.c -+loongarch_KEXEC_SRCS += kexec/arch/loongarch/kexec-pez-loongarch.c - - loongarch_MEM_REGIONS = kexec/mem_regions.c - -diff --git a/kexec/arch/loongarch/image-header.h b/kexec/arch/loongarch/image-header.h -index 3b75765..223d81f 100644 ---- a/kexec/arch/loongarch/image-header.h -+++ b/kexec/arch/loongarch/image-header.h -@@ -33,6 +33,7 @@ struct loongarch_image_header { - }; - - static const uint8_t loongarch_image_pe_sig[2] = {'M', 'Z'}; -+static const uint8_t loongarch_pe_machtype[6] = {'P','E', 0x0, 0x0, 0x64, 0x62}; - - /** - * loongarch_header_check_pe_sig - Helper to check the loongarch image header. -diff --git a/kexec/arch/loongarch/kexec-loongarch.c b/kexec/arch/loongarch/kexec-loongarch.c -index f47c998..62ff8fd 100644 ---- a/kexec/arch/loongarch/kexec-loongarch.c -+++ b/kexec/arch/loongarch/kexec-loongarch.c -@@ -165,6 +165,7 @@ int get_memory_ranges(struct memory_range **range, int *ranges, - - struct file_type file_type[] = { - {"elf-loongarch", elf_loongarch_probe, elf_loongarch_load, elf_loongarch_usage}, -+ {"pez-loongarch", pez_loongarch_probe, pez_loongarch_load, pez_loongarch_usage}, - {"pei-loongarch", pei_loongarch_probe, pei_loongarch_load, pei_loongarch_usage}, - }; - int file_types = sizeof(file_type) / sizeof(file_type[0]); -diff --git a/kexec/arch/loongarch/kexec-loongarch.h b/kexec/arch/loongarch/kexec-loongarch.h -index 5120a26..2c7624f 100644 ---- a/kexec/arch/loongarch/kexec-loongarch.h -+++ b/kexec/arch/loongarch/kexec-loongarch.h -@@ -27,6 +27,10 @@ int pei_loongarch_probe(const char *buf, off_t len); - int pei_loongarch_load(int argc, char **argv, const char *buf, off_t len, - struct kexec_info *info); - void pei_loongarch_usage(void); -+int pez_loongarch_probe(const char *kernel_buf, off_t kernel_size); -+int pez_loongarch_load(int argc, char **argv, const char *buf, off_t len, -+ struct kexec_info *info); -+void pez_loongarch_usage(void); - - int loongarch_process_image_header(const struct loongarch_image_header *h); - -diff --git a/kexec/arch/loongarch/kexec-pez-loongarch.c b/kexec/arch/loongarch/kexec-pez-loongarch.c -new file mode 100644 -index 0000000..942a47c ---- /dev/null -+++ b/kexec/arch/loongarch/kexec-pez-loongarch.c -@@ -0,0 +1,90 @@ -+/* -+ * LoongArch PE compressed Image (vmlinuz, ZBOOT) support. -+ * Based on arm64 code -+ */ -+ -+#define _GNU_SOURCE -+#include -+#include -+#include -+#include "kexec.h" -+#include "kexec-loongarch.h" -+#include -+#include "arch/options.h" -+ -+static int kernel_fd = -1; -+static off_t decompressed_size; -+ -+/* Returns: -+ * -1 : in case of error/invalid format (not a valid PE+compressed ZBOOT format. -+ */ -+int pez_loongarch_probe(const char *kernel_buf, off_t kernel_size) -+{ -+ int ret = -1; -+ const struct loongarch_image_header *h; -+ char *buf; -+ off_t buf_sz; -+ -+ buf = (char *)kernel_buf; -+ buf_sz = kernel_size; -+ if (!buf) -+ return -1; -+ h = (const struct loongarch_image_header *)buf; -+ -+ dbgprintf("%s: PROBE.\n", __func__); -+ if (buf_sz < sizeof(struct loongarch_image_header)) { -+ dbgprintf("%s: Not large enough to be a PE image.\n", __func__); -+ return -1; -+ } -+ if (!loongarch_header_check_pe_sig(h)) { -+ dbgprintf("%s: Not an PE image.\n", __func__); -+ return -1; -+ } -+ -+ if (buf_sz < sizeof(struct loongarch_image_header) + h->pe_header) { -+ dbgprintf("%s: PE image offset larger than image.\n", __func__); -+ return -1; -+ } -+ -+ if (memcmp(&buf[h->pe_header], -+ loongarch_pe_machtype, sizeof(loongarch_pe_machtype))) { -+ dbgprintf("%s: PE header doesn't match machine type.\n", __func__); -+ return -1; -+ } -+ -+ ret = pez_prepare(buf, buf_sz, &kernel_fd, &decompressed_size); -+ -+ /* Fixme: add sanity check of the decompressed kernel before return */ -+ return ret; -+} -+ -+int pez_loongarch_load(int argc, char **argv, const char *buf, off_t len, -+ struct kexec_info *info) -+{ -+ if (kernel_fd > 0 && decompressed_size > 0) { -+ char *kbuf; -+ off_t nread; -+ -+ info->kernel_fd = kernel_fd; -+ /* -+ * slurp_fd will close kernel_fd, but it is safe here -+ * due to no kexec_file_load support. -+ */ -+ kbuf = slurp_fd(kernel_fd, NULL, decompressed_size, &nread); -+ if (!kbuf || nread != decompressed_size) { -+ dbgprintf("%s: slurp_fd failed.\n", __func__); -+ return -1; -+ } -+ return pei_loongarch_load(argc, argv, kbuf, decompressed_size, info); -+ } -+ -+ dbgprintf("%s: wrong kernel file descriptor.\n", __func__); -+ return -1; -+} -+ -+void pez_loongarch_usage(void) -+{ -+ printf( -+" An LoongArch vmlinuz, PE image of a compressed, little endian.\n" -+" kernel, built with ZBOOT enabled.\n\n"); -+} --- -2.41.0 - diff --git a/README.packit b/README.packit index daffcaa..d529207 100644 --- a/README.packit +++ b/README.packit @@ -1,3 +1,3 @@ This repository is maintained by packit. https://packit.dev/ -The file was generated using packit 0.80.0. +The file was generated using packit 0.87.1. diff --git a/kexec-tools.spec b/kexec-tools.spec index 5040a4f..e1b0bff 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -4,8 +4,8 @@ %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools -Version: 2.0.27 -Release: 5%{?dist} +Version: 2.0.28 +Release: 1%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -105,18 +105,6 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # -# kexec-tools 2.0.27.git -# Author: Simon Horman -Patch602: 0001-kexec-tools-2.0.27.git.patch -# build: fix tarball creation -# Author: Leah Neukirchen -Patch603: 0002-build-fix-tarball-creation.patch -# zboot: enable arm64 kexec_load for zboot image -# Author: Dave Young -Patch604: 0003-zboot-enable-arm64-kexec_load-for-zboot-image.patch -# zboot: add loongarch kexec_load support -# Author: Dave Young -Patch605: 0004-zboot-add-loongarch-kexec_load-support.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -132,10 +120,6 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} -%patch602 -p1 -%patch603 -p1 -%patch604 -p1 -%patch605 -p1 %ifarch ppc %define archdef ARCH=ppc @@ -375,6 +359,11 @@ fi %endif %changelog +* Wed Jan 17 2024 Coiby Xu - 2.0.28-1 +- kexec-tools 2.0.28 (Simon Horman) +- Use the same /etc/resolve.conf in kdump initrd if it's managed manually +- dracut-module-setup: consolidate s390 network device config + * Mon Dec 11 2023 Coiby Xu - 2.0.27-5 - Let %post scriptlet always exits with the zero exit status diff --git a/sources b/sources index fd41a48..61c3db7 100644 --- a/sources +++ b/sources @@ -1,4 +1,3 @@ -SHA512 (kexec-tools-2.0.27.tar.xz) = 30b5ef7c2075dfd11fd1c3c33abe6b60673400257668d60145be08a2472356c7191a0810095da0fa32e327b9806a7578c73129ac0550d26c28ea6571c88c7b3c -SHA512 (makedumpfile-1.7.2.tar.gz) = 324e303dd5f507703f66e2bd5dc9d24f9f50ba797be70c05702008ba77078f61ffcc884796ddf9ab737de1d124c3a9d881ab5ce4f3f459690ec00055af25ea9e +SHA512 (kexec-tools-2.0.28.tar.xz) = 889a7bf1d26bb309e4ff7ce1c8dbcf48c01e47221ea3acf1c4ef2a98a652c496e31bddcdb627d3adebd85f7541d1fb9122c60e741e10b3726e31a9733cadc753 SHA512 (eppic-e8844d3.tar.gz) = d86b9f90c57e694107272d8f71b87f66a30743b9530480fb6f665026bbada4c6b0205a83e40b5383663a945681cfbfcf1ee79469fc219ddf679473c4b2290763 SHA512 (makedumpfile-1.7.4.tar.gz) = 6c3455b711bd4e120173ee07fcc5ff708ae6d34eaee0f4c135eca7ee0e0475b4d391429c23cf68e848b156ee3edeab956e693a390d67ccc634c43224c7129a96 From 753e5060d7b6ed5c5f81b14cbdd139f56b99216a Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Sun, 21 Jan 2024 00:15:51 +0000 Subject: [PATCH 406/454] Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index e1b0bff..c4c1664 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.28 -Release: 1%{?dist} +Release: 2%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -359,6 +359,9 @@ fi %endif %changelog +* Sun Jan 21 2024 Fedora Release Engineering - 2.0.28-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild + * Wed Jan 17 2024 Coiby Xu - 2.0.28-1 - kexec-tools 2.0.28 (Simon Horman) - Use the same /etc/resolve.conf in kdump initrd if it's managed manually From 6943de2cdcdb23534654ddaa883e42bdd4adc33d Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Fri, 5 Jan 2024 14:40:12 +0800 Subject: [PATCH 407/454] Print error msg when forget to specify user for ssh target Resolves: https://issues.redhat.com/browse/FC-1046 We require that be explicitly specified in 'ssh @'. When forgetting to specify, such as 'ssh 192.168.10.2', a useful error log should be printed instead of exiting directly. Signed-off-by: Lichen Liu Reviewed-by: Philipp Rudo --- kdumpctl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kdumpctl b/kdumpctl index 3da5fff..45277a7 100755 --- a/kdumpctl +++ b/kdumpctl @@ -748,7 +748,12 @@ check_ssh_config() [[ "${OPT[_fstype]}" == ssh ]] || return 0 target=$(ssh -G "${OPT[_target]}" | sed -n -e "s/^hostname[[:space:]]\+\([^[:space:]]*\).*$/\1/p") - [[ ${OPT[_target]} =~ .*@.* ]] || return 1 + + if [[ ${OPT[_target]} != *@* ]]; then + derror "Please verify that $KDUMP_CONFIG_FILE contains 'ssh @' and that it is properly formatted." + return 1 + fi + if [[ ${OPT[_target]#*@} != "$target" ]]; then derror "Invalid ssh destination ${OPT[_target]} provided." return 1 From 468336700df86b52cd673d68561ba460ff2390be Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Mon, 22 Jan 2024 15:59:09 +0800 Subject: [PATCH 408/454] dracut-module-setup: Skip initrd-cleanup and initrd-parse-etc in kdump When using multipath devices as the target for kdump, if user_friendly_name is also specified, devices default to names like "mpath*", e.g., mpatha. In dracut, we obtain a persistent device name via get_persistent_dev. However, dracut currently believes using /dev/mapper/mpath* could cause issues, thus alternatively names are used, here it's /dev/disk/by-uuid/. During the kdump boot progress, the /dev/disk/by-uuid/ will exist as soon as one of the path devices exists, but it won't be usable by systemd, since multipathd will claim that device as a path device. Then multipathd will get stopped before it can create the multipath device. Without user_friendly_name, /dev/mapper/ is considered a persistent device name, avoiding the issue. The exit of multipathd is due to two dependencies in the current dracut module 90multipath/multipathd.service, "Before=initrd-cleanup.service" and "Conflicts=initrd-cleanup.service". As per man 5 systemd.unit, if A.service has "Conflicts=B.service", starting B.service will stop A.service. This is useful during normal boot. However, we will never switch-root after capturing vmcore in kdump. We need to ensure that multipathd is not killed due to such dependency issue. Without modifying multipathd.service, we add ConditionPathExists=!/proc/vmcore to skip initrd-cleanup.service in kdump. This approach is beneficial as it avoid the potential termination of other services that conflict with initrd-cleanup.service. Also skip initrd-parse-etc.service as it will try to start initrd-cleanup.service. Both of these services are used for switch root, so they can be safely skipped in kdump. Suggested-by: Benjamin Marzinski Suggested-by: Dave Young Signed-off-by: Lichen Liu Reviewed-by: Philipp Rudo --- dracut-module-setup.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index e39bc13..daa6b26 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1070,6 +1070,15 @@ install() { 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ "${initdir}/etc/lvm/lvm.conf" &> /dev/null + # Skip initrd-cleanup.service and initrd-parse-etc.service becasue we don't + # need to switch root. Instead of removing them, we use ConditionPathExists + # to check if /proc/vmcore exists to determine if we are in kdump. + sed -i '/\[Unit\]/a ConditionPathExists=!\/proc\/vmcore' \ + "${initdir}/${systemdsystemunitdir}/initrd-cleanup.service" &> /dev/null + + sed -i '/\[Unit\]/a ConditionPathExists=!\/proc\/vmcore' \ + "${initdir}/${systemdsystemunitdir}/initrd-parse-etc.service" &> /dev/null + # Save more memory by dropping switch root capability dracut_no_switch_root } From 95f086ca9f24ee7b07ed74921b05e9c1c01e8fe3 Mon Sep 17 00:00:00 2001 From: Fedora Release Engineering Date: Wed, 24 Jan 2024 23:55:58 +0000 Subject: [PATCH 409/454] Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild --- kexec-tools.spec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index c4c1664..c15c994 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.28 -Release: 2%{?dist} +Release: 3%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -359,6 +359,9 @@ fi %endif %changelog +* Wed Jan 24 2024 Fedora Release Engineering - 2.0.28-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild + * Sun Jan 21 2024 Fedora Release Engineering - 2.0.28-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild From 97b3b962a956b16ea21424c7d24630c657a59845 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sat, 4 Nov 2023 12:26:27 +0800 Subject: [PATCH 410/454] Get rid of "grep: warning: stray \ before /" Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2242185 grep (3.8) warnings when running the unit tests or running "kdumpctl reset-crashkernel" on >= F39, # unit tests Examples: 1) kdumpctl _find_kernel_path_by_release() returns the kernel path for the given release When call _find_kernel_path_by_release vmlinuz-6.2.11-200.fc37.x86_64 1.1) WARNING: There was output to stderr but not found expectation stderr: grep: warning: stray \ before / # spec/kdumpctl_general_spec.sh:169-172 # kdumpctl reset-crashkernel grep: warning: stray \ before / kdump: Updated crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M for kernel=/boot/vmlinuz-6.6.8-200.fc39.x86_64. Please reboot the system for the change to take effect. This warning can be reproduced by echo 'kernel="/boot/vmlinuz-6.4.6-200.fc38.x86_64"' | grep -E "^kernel=.*$_release(\/\w+)?\"$" This patch removes unneeded backslash. It also adds a test for systemd-boot path. And for simplification, Parameters:dynamic is now used to generate test data dynamically. Fixes: 8af05dc4 ("kdumpctl: Add support for systemd-boot paths") Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdumpctl | 2 +- spec/kdumpctl_general_spec.sh | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/kdumpctl b/kdumpctl index 45277a7..30eb27d 100755 --- a/kdumpctl +++ b/kdumpctl @@ -1412,7 +1412,7 @@ _find_kernel_path_by_release() # Insert '/' before '+' to cope with grep's EREs _release=${_release//+/\\+} - _grubby_kernel_str=$(grubby --info ALL | grep -E "^kernel=.*$_release(\/\w+)?\"$") + _grubby_kernel_str=$(grubby --info ALL | grep -E "^kernel=.*$_release(/\w+)?\"$") _kernel_path=$(_filter_grubby_kernel_str "$_grubby_kernel_str") if [[ -z $_kernel_path ]]; then ddebug "kernel $_release doesn't exist" diff --git a/spec/kdumpctl_general_spec.sh b/spec/kdumpctl_general_spec.sh index 243aeca..b8a871c 100644 --- a/spec/kdumpctl_general_spec.sh +++ b/spec/kdumpctl_general_spec.sh @@ -156,16 +156,32 @@ Describe 'kdumpctl' End Describe '_find_kernel_path_by_release()' + # When the array length changes, the Parameters:dynamic should change as well + kernel_paths=(/boot/vmlinuz-6.2.11-200.fc37.x86_64 + /boot/vmlinuz-5.14.0-316.el9.aarch64+64k + /boot/vmlinuz-5.14.0-322.el9.aarch64 + /boot/efi/36b54597c46383/6.4.0-0.rc0.20230427git6e98b09da931.5.fc39.aarch64/linux) + + kernels=(vmlinuz-6.2.11-200.fc37.x86_64 + vmlinuz-5.14.0-316.el9.aarch64+64k + vmlinuz-5.14.0-322.el9.aarch64 + 6.4.0-0.rc0.20230427git6e98b09da931.5.fc39.aarch64) + grubby() { - echo -e 'kernel="/boot/vmlinuz-6.2.11-200.fc37.x86_64"\nkernel="/boot/vmlinuz-5.14.0-322.el9.aarch64"\nkernel="/boot/vmlinuz-5.14.0-316.el9.aarch64+64k"' + for key in "${!kernel_paths[@]}"; do + echo "kernel=\"${kernel_paths[$key]}\"" + done } - Parameters - # parameter answer - vmlinuz-6.2.11-200.fc37.x86_64 /boot/vmlinuz-6.2.11-200.fc37.x86_64 - vmlinuz-5.14.0-322.el9.aarch64 /boot/vmlinuz-5.14.0-322.el9.aarch64 - vmlinuz-5.14.0-316.el9.aarch64+64k /boot/vmlinuz-5.14.0-316.el9.aarch64+64k + Parameters:dynamic + # Due to a bug [1] in shellspec, hardcode the loop number instead of using the + # array length + # [1] https://github.com/shellspec/shellspec/issues/259 + for key in {0..3}; do + %data "${kernels[$key]}" "${kernel_paths[$key]}" + done End + It 'returns the kernel path for the given release' When call _find_kernel_path_by_release "$1" The output should equal "$2" From 2974fa3f262ad1ad262da33dd26eee2c1e7bfdb7 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 30 Jan 2024 01:54:05 +0800 Subject: [PATCH 411/454] kdump-dep-generator: source kdump-lib-initramfs.sh instead Currently kdump-dep-generator will source kdump-lib.sh. Notice kdump-dep-generator have #!/bin/sh so it should be POSIX, but kdump-lib.sh is a non-POSIX bash script. When Bash is configured to run in POSIX mode for #!/bin/sh scripts, it will fail with: /usr/lib/kdump/kdump-lib.sh: line 1042: syntax error near unexpected token `<' /usr/lib/kdump/kdump-lib.sh: line 1042: ` done < <( _crashkernel_parse "$ck")' This subshell call is easy to convert into a pipe but we should just source kdump-lib-initramfs.sh here, the only thing kdump-dep-generator needs is is_ssh_dump_target which is in kdump-lib-initramfs.sh, also prevents further POSIX violations. Signed-off-by: Kairui Song Reviewed-by: Philipp Rudo --- kdump-dep-generator.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdump-dep-generator.sh b/kdump-dep-generator.sh index f48c8f6..70ae621 100644 --- a/kdump-dep-generator.sh +++ b/kdump-dep-generator.sh @@ -3,7 +3,7 @@ # More details about systemd generator: # http://www.freedesktop.org/wiki/Software/systemd/Generators/ -. /usr/lib/kdump/kdump-lib.sh +. /usr/lib/kdump/kdump-lib-initramfs.sh . /usr/lib/kdump/kdump-logger.sh # If invokded with no arguments for testing purpose, output to /tmp to From 4eec72b56b89c72dde1fae681423301e1830f9e2 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 2 Feb 2024 19:39:18 +0800 Subject: [PATCH 412/454] 2.0.28 upstream release Upstream tag: v2.0.28 Upstream commit: 328de8e0 Signed-off-by: Coiby Xu --- README.packit | 2 +- ...uilding-on-x86_64-with-binutils-2.41.patch | 92 +++++++++++++++++++ ...xec-don-t-use-kexec_file_load-on-XEN.patch | 60 ++++++++++++ kexec-tools.spec | 14 ++- 4 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 kexec-tools-2.0.28-Fix-building-on-x86_64-with-binutils-2.41.patch create mode 100644 kexec-tools-2.0.28-kexec-don-t-use-kexec_file_load-on-XEN.patch diff --git a/README.packit b/README.packit index d529207..00a8c4d 100644 --- a/README.packit +++ b/README.packit @@ -1,3 +1,3 @@ This repository is maintained by packit. https://packit.dev/ -The file was generated using packit 0.87.1. +The file was generated using packit 0.89.0. diff --git a/kexec-tools-2.0.28-Fix-building-on-x86_64-with-binutils-2.41.patch b/kexec-tools-2.0.28-Fix-building-on-x86_64-with-binutils-2.41.patch new file mode 100644 index 0000000..60b15f3 --- /dev/null +++ b/kexec-tools-2.0.28-Fix-building-on-x86_64-with-binutils-2.41.patch @@ -0,0 +1,92 @@ +From 328de8e00e298f00d7ba6b25dc3950147e9642e6 Mon Sep 17 00:00:00 2001 +From: Michel Lind +Date: Tue, 30 Jan 2024 04:14:31 -0600 +Subject: [PATCH 2/2] Fix building on x86_64 with binutils 2.41 + +Newer versions of the GNU assembler (observed with binutils 2.41) will +complain about the ".arch i386" in files assembled with "as --64", +with the message "Error: 64bit mode not supported on 'i386'". + +Fix by moving ".arch i386" below the relevant ".code32" directive, so +that the assembler is no longer expecting 64-bit instructions to be used +by the time that the ".arch i386" directive is encountered. + +Based on similar iPXE fix: +https://github.com/ipxe/ipxe/commit/6ca597eee + +Signed-off-by: Michel Lind +Signed-off-by: Simon Horman +--- + purgatory/arch/i386/entry32-16-debug.S | 2 +- + purgatory/arch/i386/entry32-16.S | 2 +- + purgatory/arch/i386/entry32.S | 2 +- + purgatory/arch/i386/setup-x86.S | 2 +- + 4 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/purgatory/arch/i386/entry32-16-debug.S b/purgatory/arch/i386/entry32-16-debug.S +index 5167944..12e1164 100644 +--- a/purgatory/arch/i386/entry32-16-debug.S ++++ b/purgatory/arch/i386/entry32-16-debug.S +@@ -25,10 +25,10 @@ + .globl entry16_debug_pre32 + .globl entry16_debug_first32 + .globl entry16_debug_old_first32 +- .arch i386 + .balign 16 + entry16_debug: + .code32 ++ .arch i386 + /* Compute where I am running at (assumes esp valid) */ + call 1f + 1: popl %ebx +diff --git a/purgatory/arch/i386/entry32-16.S b/purgatory/arch/i386/entry32-16.S +index c051aab..eace095 100644 +--- a/purgatory/arch/i386/entry32-16.S ++++ b/purgatory/arch/i386/entry32-16.S +@@ -20,10 +20,10 @@ + #undef i386 + .text + .globl entry16, entry16_regs +- .arch i386 + .balign 16 + entry16: + .code32 ++ .arch i386 + /* Compute where I am running at (assumes esp valid) */ + call 1f + 1: popl %ebx +diff --git a/purgatory/arch/i386/entry32.S b/purgatory/arch/i386/entry32.S +index f7a494f..8ce9e31 100644 +--- a/purgatory/arch/i386/entry32.S ++++ b/purgatory/arch/i386/entry32.S +@@ -20,10 +20,10 @@ + #undef i386 + + .text +- .arch i386 + .globl entry32, entry32_regs + entry32: + .code32 ++ .arch i386 + + /* Setup a gdt that should that is generally usefully */ + lgdt %cs:gdt +diff --git a/purgatory/arch/i386/setup-x86.S b/purgatory/arch/i386/setup-x86.S +index 201bb2c..a212eed 100644 +--- a/purgatory/arch/i386/setup-x86.S ++++ b/purgatory/arch/i386/setup-x86.S +@@ -21,10 +21,10 @@ + #undef i386 + + .text +- .arch i386 + .globl purgatory_start + purgatory_start: + .code32 ++ .arch i386 + + /* Load a gdt so I know what the segment registers are */ + lgdt %cs:gdt +-- +2.43.0 + diff --git a/kexec-tools-2.0.28-kexec-don-t-use-kexec_file_load-on-XEN.patch b/kexec-tools-2.0.28-kexec-don-t-use-kexec_file_load-on-XEN.patch new file mode 100644 index 0000000..2af234b --- /dev/null +++ b/kexec-tools-2.0.28-kexec-don-t-use-kexec_file_load-on-XEN.patch @@ -0,0 +1,60 @@ +From 94fbe64fb22d61726ca0c0996987574b6c783c19 Mon Sep 17 00:00:00 2001 +From: Jiri Bohac +Date: Tue, 16 Jan 2024 18:14:31 +0100 +Subject: [PATCH 1/2] kexec: don't use kexec_file_load on XEN + +Since commit 29fe5067ed07 ("kexec: make -a the default") +kexec tries the kexec_file_load syscall first and only falls back to kexec_load on +selected error codes. + +This effectively breaks kexec on XEN, unless -c is pecified to force the kexec_load +syscall. + +The XEN-specific functions (xen_kexec_load / xen_kexec_unload) are only called +from my_load / k_unload, i.e. the kexec_load code path. + +With -p (panic kernel) kexec_file_load on XEN fails with -EADDRNOTAVAIL (crash +kernel reservation is ignored by the kernel on XEN), which is not in the list +of return codes that cause the fallback to kexec_file. + +Without -p kexec_file_load actualy leads to a kernel oops on v6.4.0 +(needs to be dubugged separately). + +Signed-off-by: Jiri Bohac +Fixes: 29fe5067ed07 ("kexec: make -a the default") +Signed-off-by: Simon Horman +--- + kexec/kexec.8 | 1 + + kexec/kexec.c | 4 ++++ + 2 files changed, 5 insertions(+) + +diff --git a/kexec/kexec.8 b/kexec/kexec.8 +index b969cea..9e995fe 100644 +--- a/kexec/kexec.8 ++++ b/kexec/kexec.8 +@@ -162,6 +162,7 @@ Specify that the new kernel is of this + .TP + .BI \-s\ (\-\-kexec-file-syscall) + Specify that the new KEXEC_FILE_LOAD syscall should be used exclusively. ++Ignored on XEN. + .TP + .BI \-c\ (\-\-kexec-syscall) + Specify that the old KEXEC_LOAD syscall should be used exclusively. +diff --git a/kexec/kexec.c b/kexec/kexec.c +index 08edfca..9d0ec46 100644 +--- a/kexec/kexec.c ++++ b/kexec/kexec.c +@@ -1685,6 +1685,10 @@ int main(int argc, char *argv[]) + } + } + } ++ if (xen_present()) { ++ do_kexec_file_syscall = 0; ++ do_kexec_fallback = 0; ++ } + if (do_kexec_file_syscall) { + if (do_load_jump_back_helper && !do_kexec_fallback) + die("--load-jump-back-helper not supported with kexec_file_load\n"); +-- +2.43.0 + diff --git a/kexec-tools.spec b/kexec-tools.spec index c15c994..af24741 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.28 -Release: 3%{?dist} +Release: 4%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -89,6 +89,9 @@ Requires: systemd-udev%{?_isa} # # Patches 101 through 200 are meant for x86_64 kexec-tools enablement # +# Fix building on x86_64 with binutils 2.41 +# Author: Michel Lind +Patch101: kexec-tools-2.0.28-Fix-building-on-x86_64-with-binutils-2.41.patch # # Patches 301 through 400 are meant for ppc64 kexec-tools enablement @@ -105,6 +108,9 @@ Requires: systemd-udev%{?_isa} # # Patches 601 onward are generic patches # +# kexec: don't use kexec_file_load on XEN +# Author: Jiri Bohac +Patch601: kexec-tools-2.0.28-kexec-don-t-use-kexec_file_load-on-XEN.patch %description kexec-tools provides /sbin/kexec binary that facilitates a new @@ -120,6 +126,8 @@ mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} +%patch 101 -p1 +%patch 601 -p1 %ifarch ppc %define archdef ARCH=ppc @@ -359,6 +367,10 @@ fi %endif %changelog +* Fri Feb 02 2024 Coiby Xu - 2.0.28-4 +- kexec: don't use kexec_file_load on XEN +- Fix building on x86_64 with binutils 2.41 + * Wed Jan 24 2024 Fedora Release Engineering - 2.0.28-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild From ec3bccdf326881decd13f0ac7b4558f4a22875bd Mon Sep 17 00:00:00 2001 From: Carl George Date: Fri, 23 Feb 2024 16:32:28 -0600 Subject: [PATCH 413/454] Add a makedumpfile subpackage --- kexec-tools.spec | 72 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 21 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index af24741..6104e46 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.28 -Release: 4%{?dist} +Release: 5%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -60,7 +60,7 @@ Source201: dracut-fadump-module-setup.sh Requires(post): servicelog Recommends: keyutils %endif -Requires(pre): coreutils sed zlib +Requires(pre): coreutils sed Requires: dracut >= 058 Requires: dracut-network >= 058 Requires: dracut-squash >= 058 @@ -71,8 +71,6 @@ Recommends: binutils Recommends: grubby Recommends: hostname BuildRequires: make -BuildRequires: zlib-devel elfutils-devel glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel libzstd-devel -BuildRequires: pkgconfig intltool gettext BuildRequires: systemd-rpm-macros BuildRequires: automake autoconf libtool @@ -119,6 +117,37 @@ normal or a panic reboot. This package contains the /sbin/kexec binary and ancillary utilities that together form the userspace component of the kernel's kexec feature. + +%package -n makedumpfile +Version: %{mkdf_ver} +Summary: make a small dumpfile of kdump +License: GPL-2.0-only +URL: https://github.com/makedumpfile/makedumpfile + +Conflicts: kexec-tools < 2.0.28-5 +Requires(pre): zlib +BuildRequires: make +BuildRequires: gcc +BuildRequires: zlib-devel +BuildRequires: elfutils-devel +BuildRequires: glib2-devel +BuildRequires: bzip2-devel +BuildRequires: ncurses-devel +BuildRequires: bison +BuildRequires: flex +BuildRequires: lzo-devel +BuildRequires: snappy-devel +BuildRequires: libzstd-devel +BuildRequires: pkgconfig +BuildRequires: intltool +BuildRequires: gettext + + +%description -n makedumpfile +makedumpfile is a tool to compress and filter out unneeded data from kernel +dumps to reduce its file size. It is typically used with the kdump mechanism. + + %prep %setup -q @@ -159,11 +188,12 @@ cp %{SOURCE34} . %{SOURCE4} %{_target_cpu} > kdump.conf make -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 + +# makedumpfile make -C eppic-%{eppic_ver}/libeppic make -C makedumpfile-%{mkdf_ver} LINKTYPE=dynamic USELZO=on USESNAPPY=on USEZSTD=on make -C makedumpfile-%{mkdf_ver} LDFLAGS="$LDFLAGS -I../eppic-%{eppic_ver}/libeppic -L../eppic-%{eppic_ver}/libeppic" eppic_makedumpfile.so -%endif + %install mkdir -p -m755 $RPM_BUILD_ROOT/usr/sbin @@ -221,7 +251,7 @@ install -m 755 -D %{SOURCE22} $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-gener install -m 755 -D %{SOURCE30} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-kdump.install install -m 755 -D %{SOURCE33} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/92-crashkernel.install -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 +# makedumpfile install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.8 $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8 install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf.5 $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5 @@ -229,7 +259,6 @@ install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf $RPM_BUILD_ROOT/%{_sys install -m 755 makedumpfile-%{mkdf_ver}/eppic_makedumpfile.so $RPM_BUILD_ROOT/%{_libdir}/eppic_makedumpfile.so mkdir -p $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ install -m 644 makedumpfile-%{mkdf_ver}/eppic_scripts/* $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ -%endif %define dracutdir %{_prefix}/lib/dracut/modules.d %define remove_prefix() %(echo -n %2|sed 's/.*%1-//g') @@ -313,9 +342,6 @@ fi %files /usr/sbin/kexec -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 -/usr/sbin/makedumpfile -%endif %ifarch ppc64 ppc64le /usr/sbin/mkfadumprd %{_prefix}/lib/kernel/install.d/60-fadump.install @@ -325,9 +351,6 @@ fi %{_bindir}/* %{_datadir}/kdump %{_prefix}/lib/kdump -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 -%{_sysconfdir}/makedumpfile.conf.sample -%endif %config(noreplace,missingok) %{_sysconfdir}/sysconfig/kdump %config(noreplace,missingok) %verify(not mtime) %{_sysconfdir}/kdump.conf %ifnarch s390x @@ -342,12 +365,9 @@ fi %dir %{_sharedstatedir}/kdump %{_mandir}/man8/kdumpctl.8.gz %{_mandir}/man8/kexec.8.gz -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 -%{_mandir}/man8/makedumpfile.8.gz -%endif %{_mandir}/man8/mkdumprd.8.gz %{_mandir}/man8/vmcore-dmesg.8.gz -%{_mandir}/man5/* +%{_mandir}/man5/kdump.conf.5.gz %{_unitdir}/kdump.service %{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh %{_prefix}/lib/kernel/install.d/60-kdump.install @@ -361,12 +381,22 @@ fi %doc kdump-in-cluster-environment.txt %doc live-image-kdump-howto.txt %doc crashkernel-howto.txt -%ifarch %{ix86} x86_64 ppc64 s390x ppc64le aarch64 + + +%files -n makedumpfile +%license makedumpfile-%{mkdf_ver}/COPYING +%{_sbindir}/makedumpfile +%{_mandir}/man5/makedumpfile.conf.5.gz +%{_mandir}/man8/makedumpfile.8.gz +%{_sysconfdir}/makedumpfile.conf.sample %{_libdir}/eppic_makedumpfile.so -/usr/share/makedumpfile/ -%endif +%{_datadir}/makedumpfile/ + %changelog +* Fri Feb 23 2024 Carl George - 2.0.28-5 +- Add a makedumpfile subpackage + * Fri Feb 02 2024 Coiby Xu - 2.0.28-4 - kexec: don't use kexec_file_load on XEN - Fix building on x86_64 with binutils 2.41 From f9986edd25e8b414b2fc7f11f08d6d8f51a9b843 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sat, 16 Mar 2024 10:22:54 +0800 Subject: [PATCH 414/454] Release 2.0.28-6 Resovles: https://bugzilla.redhat.com/show_bug.cgi?id=2269640 Let kexec-tools depends on makedumpfile. Signed-off-by: Coiby Xu --- kexec-tools.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 6104e46..0a0b342 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.28 -Release: 5%{?dist} +Release: 6%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -61,6 +61,7 @@ Requires(post): servicelog Recommends: keyutils %endif Requires(pre): coreutils sed +Requires: makedumpfile Requires: dracut >= 058 Requires: dracut-network >= 058 Requires: dracut-squash >= 058 @@ -394,6 +395,9 @@ fi %changelog +* Sat Mar 16 2024 Coiby Xu - 2.0.28-6 +- let kexec-tools depends on makedumpfile + * Fri Feb 23 2024 Carl George - 2.0.28-5 - Add a makedumpfile subpackage From b6a066db5368d53a5e460ca1c948c0b43d66b1ef Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 8 Feb 2024 17:06:11 +0100 Subject: [PATCH 415/454] Supported targets: Import from CentOS Stream 9 In CentOS Stream a list of supported targets is maintained. Where "supported" means that these targets are tested regularly. Even though there are some small differences between CentOS Stream and Fedora when it comes to provided/supported packages and kernel configs, having this list in Fedora as well makes sense. As it provides a entry point for users to find out if a given setup is meant to work or not. Thus include the supported-kdump-targets.txt from CentOS Stream 9 [1] into Fedora. [1] https://gitlab.com/redhat/centos-stream/rpms/kexec-tools/-/blob/0a09d12d8914dd06929aa7de159c7209393c4bfa/supported-kdump-targets.txt Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- kexec-tools.spec | 3 + supported-kdump-targets.txt | 121 ++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 supported-kdump-targets.txt diff --git a/kexec-tools.spec b/kexec-tools.spec index 0a0b342..304bbb7 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -39,6 +39,7 @@ Source34: crashkernel-howto.txt Source35: kdump-migrate-action.sh Source36: kdump-restart.sh Source37: 60-fadump.install +Source38: supported-kdump-targets.txt ####################################### # These are sources for mkdumpramfs @@ -183,6 +184,7 @@ cp %{SOURCE21} . cp %{SOURCE26} . cp %{SOURCE27} . cp %{SOURCE34} . +cp %{SOURCE38} . # Generate sysconfig file %{SOURCE3} %{_target_cpu} > kdump.sysconfig @@ -382,6 +384,7 @@ fi %doc kdump-in-cluster-environment.txt %doc live-image-kdump-howto.txt %doc crashkernel-howto.txt +%doc supported-kdump-targets.txt %files -n makedumpfile diff --git a/supported-kdump-targets.txt b/supported-kdump-targets.txt new file mode 100644 index 0000000..f282adf --- /dev/null +++ b/supported-kdump-targets.txt @@ -0,0 +1,121 @@ +Supported Kdump Targets + +This document try to list all supported kdump targets, and those supported +or unknown/tech-preview targets, this can help users to decide whether a dump +solution is available. + +Dump Target support status +========================== +This section tries to come up with some kind of guidelines in terms of +what dump targets are supported/not supported. Whatever is listed here +is not binding in any manner. It is just sharing of current understanding +and if something is not right, this section needs to be edited. + +Following are 3 lists. First one contains supported targets. These are +generic configurations which should work and some configuration most +likely has worked in testing. Second list is known unsupported targets. +These targets we know either don't work or we don't support. And third +list is unknown/tech-preview. We either don't yet know the status of kdump +on these targets or these are under tech-preview. + +Note, these lists are not set in stone and can be changed at any point of +time. Also these lists might not be complete. We will add/remove items to +it as we get more testing information. Also, there are many corner cases +which can't possibly be listed. For example in general we might be +supporting software iscsi but there might be some configurations of it +which don't work. + +So if any target is listed in supported section, it does not mean it works +in all possible configurations. It just means that in common configurations +it should work but there can be issues with particular configurations which +are not supported. As we come to know of particular issues, we will keep on +updating lists accordingly. + + +Supported Dump targets +---------------------- +storage: + LVM volume + Thin provisioning volume + FC disks (qla2xxx, lpfc, bnx2fc, bfa) + software initiator based iSCSI + software RAID (mdraid) + hardware RAID (smartpqi, hpsa, megaraid, mpt3sas, aacraid, mpi3mr) + SCSI/SATA disks + iSCSI HBA (all offload) + hardware FCoE (qla2xxx, lpfc) + software FCoE (bnx2fc) (Extra configuration required, + please read "Note on FCoE" section below) + NVMe-FC (qla2xxx, lpfc) + +network: + Hardware using kernel modules: (igb, ixgbe, ice, i40e, e1000e, igc, + tg3, bnx2x, bnxt_en, qede, cxgb4, be2net, enic, sfc, mlx4_en, + mlx5_core, r8169, atlantic, nfp, ionic; nicvf (aarch64 only)) + protocol: ipv4 + bonding + vlan + bridge + vlan tagged bonding + bridge over bond/vlan + +hypervisor: + kvm + xen (Supported in select configurations only) + +filesystem: + ext[234] + xfs + nfs + virtiofs + +firmware: + BIOS + UEFI + +hypervisor: + VMWare ESXi 4.x 5.x would not be tested/supported any more. + only support ESXi 6.6, 6.7, 7.0 + Hyper-V 2012 R2 (RHEL Gen1 UP Guest only), later version will + also be tested/supported + +Unsupported Dump targets +------------------------ +storage: + BIOS RAID + Software iSCSI with iBFT (bnx2i, cxgb3i, cxgb4i) + Software iSCSI with hybrid (be2iscsi) + FCoE + legacy IDE + glusterfs + gfs2/clvm/halvm + +network: + hardware using kernel modules: (sfc SRIOV, cxgb4vf, pch_gbe) + protocol: ipv6 + wireless + Infiniband (IB) + vlan over bridge/team + +filesystem: + btrfs + +Unknown/tech-preview +-------------------- +storage: + PCI Express based SSDs + +hypervisor: + Hyper-V 2008 + Hyper-V 2012 + + +Note on FCoE +===================== +If you are trying to dump to a software FCoE target, you may encounter OOM +issue, because some software FCoE requires more memory to work. In such case, +you may need to increase the kdump reserved memory size in "crashkernel=" +kernel parameter. + +For hardware FCoE, kdump should work naturally as firmware will do the +initialization job. The capture kernel and kdump tools will run just fine. From d2b6547f55ca960463de6dca6791db3c7d10ec06 Mon Sep 17 00:00:00 2001 From: Philipp Rudo Date: Thu, 8 Feb 2024 17:06:12 +0100 Subject: [PATCH 416/454] Supported targets: Merge hypervisor sections The supported targets list has two separate hypervisor sections. Merge them into one. Signed-off-by: Philipp Rudo Reviewed-by: Coiby Xu --- supported-kdump-targets.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/supported-kdump-targets.txt b/supported-kdump-targets.txt index f282adf..936a42b 100644 --- a/supported-kdump-targets.txt +++ b/supported-kdump-targets.txt @@ -59,10 +59,6 @@ network: vlan tagged bonding bridge over bond/vlan -hypervisor: - kvm - xen (Supported in select configurations only) - filesystem: ext[234] xfs @@ -74,6 +70,8 @@ firmware: UEFI hypervisor: + kvm + xen (selected configurations only) VMWare ESXi 4.x 5.x would not be tested/supported any more. only support ESXi 6.6, 6.7, 7.0 Hyper-V 2012 R2 (RHEL Gen1 UP Guest only), later version will From 44a1b7da908a52c15a2b7ed286b59cfe7319b4c9 Mon Sep 17 00:00:00 2001 From: Sourabh Jain Date: Wed, 28 Feb 2024 22:51:15 +0530 Subject: [PATCH 417/454] ppc64le: replace kernel cmdline maxcpu=1 with nr_cpus=1 With patch series [1], PowerPC supports nr_cpus=1, so use nr_cpus=1 instead of maxcpu=1 in the kdump environment. Note this changes is dependent on kernel changes [1] [1] https://lore.kernel.org/all/170800202447.601034.7290612623478478380.b4-ty@ellerman.id.au/#t Signed-off-by: Sourabh Jain Cc: Hari Bathini Cc: Mahesh Salgaonkar Acked-by: Pingfan Liu --- gen-kdump-sysconfig.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen-kdump-sysconfig.sh b/gen-kdump-sysconfig.sh index 4a28350..78b0bb7 100755 --- a/gen-kdump-sysconfig.sh +++ b/gen-kdump-sysconfig.sh @@ -92,7 +92,7 @@ ppc64le) update_param KDUMP_COMMANDLINE_REMOVE \ "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" update_param KDUMP_COMMANDLINE_APPEND \ - "irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" + "irqpoll nr_cpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" ;; s390x) update_param KEXEC_ARGS "-s" From d6e1edc677bfd15fb4553101ffb5a34130959861 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 13 Mar 2024 14:12:58 +0800 Subject: [PATCH 418/454] doc/kdump.conf: correctly align the options Currently, the other options like "raw " become child items of the auto_reset_crashkernel option, auto_reset_crashkernel ... raw ... nfs ... ... Fix it by ending the auto_reset_crashkernel with ".RE". Fixes: 73ced7f4 ("introduce the auto_reset_crashkernel option to kdump.conf") Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump.conf.5 | 1 + 1 file changed, 1 insertion(+) diff --git a/kdump.conf.5 b/kdump.conf.5 index 0e6ff21..f738dba 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -43,6 +43,7 @@ reset-crashkernel [--kernel=path_to_kernel]" if you want to use the default value set after having enabled features like SME/SEV for a specific kernel. And you should also reboot the system for the new crashkernel value to take effect. Also see kdumpctl(8). +.RE .B raw .RS From 858de28447ff05b15ef3c7004f60c7babf1ab15c Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Wed, 13 Mar 2024 14:18:24 +0800 Subject: [PATCH 419/454] doc/kdump.conf: properly format list man files doesn't preserve line breaks. Construct a list to list the cases where additional memory will be reserved. Fixes: c752cbb2 ("Explain the auto_reset_crashkernel option in more details") Reported-by: Jie Li Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo --- kdump.conf.5 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kdump.conf.5 b/kdump.conf.5 index f738dba..20b1620 100644 --- a/kdump.conf.5 +++ b/kdump.conf.5 @@ -32,17 +32,22 @@ determine whether to reset kernel crashkernel parameter to the default value or not when kexec-tools is updated or a new kernel is installed. The default crashkernel values are different for different architectures and also take the following factors into consideration, - - AMD Secure Memory Encryption (SME) and Secure Encrypted Virtualization (SEV) - - Mellanox 5th generation network driver - - aarch64 64k kernel - - Firmware-assisted dump (FADump) - +.IP +\- AMD Secure Memory Encryption (SME) and Secure Encrypted Virtualization (SEV) +.IP +\- Mellanox 5th generation network driver +.IP +\- aarch64 64k kernel +.IP +\- Firmware-assisted dump (FADump) +.PP Since the kernel crasherkernel parameter will be only reset when kexec-tools is updated or a new kernel is installed, you need to call "kdumpctl reset-crashkernel [--kernel=path_to_kernel]" if you want to use the default value set after having enabled features like SME/SEV for a specific kernel. And you should also reboot the system for the new crashkernel value to take effect. Also see kdumpctl(8). +.PP .RE .B raw From 20dc67f0ea5bd73289be99666cf0871c5ad7a6e6 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sun, 7 Apr 2024 14:49:11 +0800 Subject: [PATCH 420/454] Release 2.0.26-7 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2269991 Signed-off-by: Coiby Xu --- ...oc_entries_in_machine_apply_elf_rel_.patch | 95 ------------- ...vmalloc-start-address-from-vmcoreinf.patch | 132 ++++++++++++++++++ kexec-tools.spec | 8 +- 3 files changed, 139 insertions(+), 96 deletions(-) delete mode 100644 kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch create mode 100644 kexec-tools-2.0.28-makedumfpile-0001-PATCH-ppc64-get-vmalloc-start-address-from-vmcoreinf.patch diff --git a/kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch b/kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch deleted file mode 100644 index 10bc5ef..0000000 --- a/kexec-tools-2.0.23-s390_handle_R_390_PLT32DBL_reloc_entries_in_machine_apply_elf_rel_.patch +++ /dev/null @@ -1,95 +0,0 @@ -commit 186e7b0752d8fce1618fa37519671c834c46340e -Author: Alexander Egorenkov -Date: Wed Dec 15 18:48:53 2021 +0100 - - s390: handle R_390_PLT32DBL reloc entries in machine_apply_elf_rel() - - Starting with gcc 11.3, the C compiler will generate PLT-relative function - calls even if they are local and do not require it. Later on during linking, - the linker will replace all PLT-relative calls to local functions with - PC-relative ones. Unfortunately, the purgatory code of kexec/kdump is - not being linked as a regular executable or shared library would have been, - and therefore, all PLT-relative addresses remain in the generated purgatory - object code unresolved. This in turn lets kexec-tools fail with - "Unknown rela relocation: 0x14 0x73c0901c" for such relocation types. - - Furthermore, the clang C compiler has always behaved like described above - and this commit should fix the purgatory code built with the latter. - - Because the purgatory code is no regular executable or shared library, - contains only calls to local functions and has no PLT, all R_390_PLT32DBL - relocation entries can be resolved just like a R_390_PC32DBL one. - - * https://refspecs.linuxfoundation.org/ELF/zSeries/lzsabi0_zSeries/x1633.html#AEN1699 - - Relocation entries of purgatory code generated with gcc 11.3 - ------------------------------------------------------------ - - $ readelf -r purgatory/purgatory.o - - Relocation section '.rela.text' at offset 0x6e8 contains 27 entries: - Offset Info Type Sym. Value Sym. Name + Addend - 00000000000c 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 - 00000000001a 001000000014 R_390_PLT32DBL 0000000000000000 sha256_starts + 2 - 000000000030 001100000014 R_390_PLT32DBL 0000000000000000 sha256_update + 2 - 000000000046 001200000014 R_390_PLT32DBL 0000000000000000 sha256_finish + 2 - 000000000050 000300000013 R_390_PC32DBL 0000000000000000 .data + 102 - 00000000005a 001300000014 R_390_PLT32DBL 0000000000000000 memcmp + 2 - ... - 000000000118 001600000014 R_390_PLT32DBL 0000000000000000 setup_arch + 2 - 00000000011e 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 - 00000000012c 000f00000014 R_390_PLT32DBL 0000000000000000 verify_sha256_digest + 2 - 000000000142 001700000014 R_390_PLT32DBL 0000000000000000 - post_verification[...] + 2 - - Relocation entries of purgatory code generated with gcc 11.2 - ------------------------------------------------------------ - - $ readelf -r purgatory/purgatory.o - - Relocation section '.rela.text' at offset 0x6e8 contains 27 entries: - Offset Info Type Sym. Value Sym. Name + Addend - 00000000000e 000300000013 R_390_PC32DBL 0000000000000000 .data + 2 - 00000000001c 001000000013 R_390_PC32DBL 0000000000000000 sha256_starts + 2 - 000000000036 001100000013 R_390_PC32DBL 0000000000000000 sha256_update + 2 - 000000000048 001200000013 R_390_PC32DBL 0000000000000000 sha256_finish + 2 - 000000000052 000300000013 R_390_PC32DBL 0000000000000000 .data + 102 - 00000000005c 001300000013 R_390_PC32DBL 0000000000000000 memcmp + 2 - ... - 00000000011a 001600000013 R_390_PC32DBL 0000000000000000 setup_arch + 2 - 000000000120 000300000013 R_390_PC32DBL 0000000000000000 .data + 122 - 000000000130 000f00000013 R_390_PC32DBL 0000000000000000 verify_sha256_digest + 2 - 000000000146 001700000013 R_390_PC32DBL 0000000000000000 post_verification[...] + 2 - - Corresponding s390 kernel discussion: - * https://lore.kernel.org/linux-s390/20211208105801.188140-1-egorenar@linux.ibm.com/T/#u - - Signed-off-by: Alexander Egorenkov - Reported-by: Tao Liu - Suggested-by: Philipp Rudo - Reviewed-by: Philipp Rudo - [hca@linux.ibm.com: changed commit message as requested by Philipp Rudo] - Signed-off-by: Heiko Carstens - Signed-off-by: Simon Horman - -diff --git a/kexec/arch/s390/kexec-elf-rel-s390.c b/kexec/arch/s390/kexec-elf-rel-s390.c -index a5e1b73455785ae3bc3aa72b3beee13ae202e82f..91ba86a9991dad4271b834fc3b24861c40309e52 100644 ---- a/kexec/arch/s390/kexec-elf-rel-s390.c -+++ b/kexec/arch/s390/kexec-elf-rel-s390.c -@@ -56,6 +56,7 @@ void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), - case R_390_PC16: /* PC relative 16 bit. */ - case R_390_PC16DBL: /* PC relative 16 bit shifted by 1. */ - case R_390_PC32DBL: /* PC relative 32 bit shifted by 1. */ -+ case R_390_PLT32DBL: /* 32 bit PC rel. PLT shifted by 1. */ - case R_390_PC32: /* PC relative 32 bit. */ - case R_390_PC64: /* PC relative 64 bit. */ - val -= address; -@@ -63,7 +64,7 @@ void machine_apply_elf_rel(struct mem_ehdr *UNUSED(ehdr), - *(unsigned short *) loc = val; - else if (r_type == R_390_PC16DBL) - *(unsigned short *) loc = val >> 1; -- else if (r_type == R_390_PC32DBL) -+ else if (r_type == R_390_PC32DBL || r_type == R_390_PLT32DBL) - *(unsigned int *) loc = val >> 1; - else if (r_type == R_390_PC32) - *(unsigned int *) loc = val; diff --git a/kexec-tools-2.0.28-makedumfpile-0001-PATCH-ppc64-get-vmalloc-start-address-from-vmcoreinf.patch b/kexec-tools-2.0.28-makedumfpile-0001-PATCH-ppc64-get-vmalloc-start-address-from-vmcoreinf.patch new file mode 100644 index 0000000..1ee904a --- /dev/null +++ b/kexec-tools-2.0.28-makedumfpile-0001-PATCH-ppc64-get-vmalloc-start-address-from-vmcoreinf.patch @@ -0,0 +1,132 @@ +From: Coiby Xu + +Subject: [PATCH] ppc64: get vmalloc start address from vmcoreinfo + +Bugzilla: https://bugzilla.redhat.com/2269991 + +commit 94241fd2feed059227a243618f2acc6aabf366e8 +Author: Aditya Gupta +Date: Sat Feb 24 00:33:42 2024 +0530 + + [PATCH] ppc64: get vmalloc start address from vmcoreinfo + + Below error was noticed when running makedumpfile on linux-next kernel + crash (linux-next tag next-20240121): + + Checking for memory holes : [100.0 %] | readpage_elf: Attempt to read non-existent page at 0xc000000000000. + [ 17.551718] kdump.sh[404]: readmem: type_addr: 0, addr:c00c000000000000, size:16384 + [ 17.551793] kdump.sh[404]: __exclude_unnecessary_pages: Can't read the buffer of struct page. + [ 17.551864] kdump.sh[404]: create_2nd_bitmap: Can't exclude unnecessary pages. + [ 17.562632] kdump.sh[404]: The kernel version is not supported. + [ 17.562708] kdump.sh[404]: The makedumpfile operation may be incomplete. + [ 17.562773] kdump.sh[404]: makedumpfile Failed. + [ 17.564335] kdump[406]: saving vmcore failed, _exitcode:1 + + Above error was due to 'vmap_area_list' and 'vmlist' symbols missing + from the vmcore. 'vmap_area_list' was removed in the linux kernel + 6.9-rc1 by the commit below: + + commit 55c49fee57af99f3c663e69dedc5b85e691bbe50 + mm/vmalloc: remove vmap_area_list + + Subsequently the commit also introduced 'VMALLOC_START' in vmcoreinfo to + get base address of vmalloc area, instead of depending on 'vmap_area_list' + + Hence if 'VMALLOC_START' symbol is there in vmcoreinfo: + 1. Set vmalloc_start based on 'VMALLOC_START' + 2. Don't error if vmap_area_list/vmlist are not defined + + Reported-by: Sachin Sant + Signed-off-by: Aditya Gupta + +Signed-off-by: Coiby Xu + +diff --git a/makedumpfile-1.7.4/arch/ppc64.c b/makedumpfile-1.7.4/arch/ppc64.c +index 3b4f91981f71d035b94282f6c7e33323a4e4c1fd..a54f9a04db7f26eac2f1bd065b134a7e2fdaeb67 100644 +--- a/makedumpfile-1.7.4/arch/ppc64.c ++++ b/makedumpfile-1.7.4/arch/ppc64.c +@@ -568,7 +568,9 @@ get_machdep_info_ppc64(void) + /* + * Get vmalloc_start value from either vmap_area_list or vmlist. + */ +- if ((SYMBOL(vmap_area_list) != NOT_FOUND_SYMBOL) ++ if (NUMBER(vmalloc_start) != NOT_FOUND_NUMBER) { ++ vmalloc_start = NUMBER(vmalloc_start); ++ } else if ((SYMBOL(vmap_area_list) != NOT_FOUND_SYMBOL) + && (OFFSET(vmap_area.va_start) != NOT_FOUND_STRUCTURE) + && (OFFSET(vmap_area.list) != NOT_FOUND_STRUCTURE)) { + if (!readmem(VADDR, SYMBOL(vmap_area_list) + OFFSET(list_head.next), +@@ -689,11 +691,16 @@ vaddr_to_paddr_ppc64(unsigned long vaddr) + if ((SYMBOL(vmap_area_list) == NOT_FOUND_SYMBOL) + || (OFFSET(vmap_area.va_start) == NOT_FOUND_STRUCTURE) + || (OFFSET(vmap_area.list) == NOT_FOUND_STRUCTURE)) { +- if ((SYMBOL(vmlist) == NOT_FOUND_SYMBOL) +- || (OFFSET(vm_struct.addr) == NOT_FOUND_STRUCTURE)) { +- ERRMSG("Can't get info for vmalloc translation.\n"); +- return NOT_PADDR; +- } ++ /* ++ * Don't depend on vmap_area_list/vmlist if vmalloc_start is set in ++ * vmcoreinfo, in that case proceed without error ++ */ ++ if (NUMBER(vmalloc_start) == NOT_FOUND_NUMBER) ++ if ((SYMBOL(vmlist) == NOT_FOUND_SYMBOL) ++ || (OFFSET(vm_struct.addr) == NOT_FOUND_STRUCTURE)) { ++ ERRMSG("Can't get info for vmalloc translation.\n"); ++ return NOT_PADDR; ++ } + } + + return ppc64_vtop_level4(vaddr); +diff --git a/makedumpfile-1.7.4/makedumpfile.c b/makedumpfile-1.7.4/makedumpfile.c +index 58c6639f289f19cdbf39ed3899be9893fdc317fe..d7f1dd41d2cab526d7d40e809ddccf656c586811 100644 +--- a/makedumpfile-1.7.4/makedumpfile.c ++++ b/makedumpfile-1.7.4/makedumpfile.c +@@ -2978,6 +2978,8 @@ read_vmcoreinfo(void) + READ_NUMBER("PAGE_OFFLINE_MAPCOUNT_VALUE", PAGE_OFFLINE_MAPCOUNT_VALUE); + READ_NUMBER("phys_base", phys_base); + READ_NUMBER("KERNEL_IMAGE_SIZE", KERNEL_IMAGE_SIZE); ++ ++ READ_NUMBER_UNSIGNED("VMALLOC_START", vmalloc_start); + #ifdef __aarch64__ + READ_NUMBER("VA_BITS", VA_BITS); + READ_NUMBER("TCR_EL1_T1SZ", TCR_EL1_T1SZ); +@@ -2989,7 +2991,6 @@ read_vmcoreinfo(void) + READ_NUMBER("VA_BITS", va_bits); + READ_NUMBER_UNSIGNED("phys_ram_base", phys_ram_base); + READ_NUMBER_UNSIGNED("PAGE_OFFSET", page_offset); +- READ_NUMBER_UNSIGNED("VMALLOC_START", vmalloc_start); + READ_NUMBER_UNSIGNED("VMALLOC_END", vmalloc_end); + READ_NUMBER_UNSIGNED("VMEMMAP_START", vmemmap_start); + READ_NUMBER_UNSIGNED("VMEMMAP_END", vmemmap_end); +diff --git a/makedumpfile-1.7.4/makedumpfile.h b/makedumpfile-1.7.4/makedumpfile.h +index c04c330b69ecbe5fb232a2eabbd2d71f14b60cc0..c31f3a4371af8aae38dcba8cac4d6de1012b4cfd 100644 +--- a/makedumpfile-1.7.4/makedumpfile.h ++++ b/makedumpfile-1.7.4/makedumpfile.h +@@ -541,8 +541,6 @@ do { \ + * The value of dependence on machine + */ + #define PAGE_OFFSET (info->page_offset) +-#define VMALLOC_START (info->vmalloc_start) +-#define VMALLOC_END (info->vmalloc_end) + #define VMEMMAP_START (info->vmemmap_start) + #define VMEMMAP_END (info->vmemmap_end) + #define PMASK (0x7ffffffffffff000UL) +@@ -2263,6 +2261,9 @@ struct number_table { + long HUGETLB_PAGE_DTOR; + long phys_base; + long KERNEL_IMAGE_SIZE; ++ ++ unsigned long vmalloc_start; ++ + #ifdef __aarch64__ + long VA_BITS; + long TCR_EL1_T1SZ; +@@ -2273,7 +2274,6 @@ struct number_table { + long va_bits; + unsigned long phys_ram_base; + unsigned long page_offset; +- unsigned long vmalloc_start; + unsigned long vmalloc_end; + unsigned long vmemmap_start; + unsigned long vmemmap_end; diff --git a/kexec-tools.spec b/kexec-tools.spec index 304bbb7..2c7d88c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.28 -Release: 6%{?dist} +Release: 7%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -112,6 +112,8 @@ Patch101: kexec-tools-2.0.28-Fix-building-on-x86_64-with-binutils-2.41.patch # Author: Jiri Bohac Patch601: kexec-tools-2.0.28-kexec-don-t-use-kexec_file_load-on-XEN.patch +Patch602: kexec-tools-2.0.28-makedumfpile-0001-PATCH-ppc64-get-vmalloc-start-address-from-vmcoreinf.patch + %description kexec-tools provides /sbin/kexec binary that facilitates a new kernel to boot using the kernel's kexec feature either on a @@ -159,6 +161,7 @@ tar -z -x -v -f %{SOURCE19} %patch 101 -p1 %patch 601 -p1 +%patch 602 -p1 %ifarch ppc %define archdef ARCH=ppc @@ -398,6 +401,9 @@ fi %changelog +* Sun Apr 07 2024 Coiby Xu - 2.0.28-7 +- Release 2.0.28-7 + * Sat Mar 16 2024 Coiby Xu - 2.0.28-6 - let kexec-tools depends on makedumpfile From 372b4c6c1597c3d9aaddda2d691260474973989e Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 29 Feb 2024 10:23:51 +0800 Subject: [PATCH 421/454] Add kdump-utils subpackage Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 220 ++++++++++++++++++++++++----------------------- 1 file changed, 113 insertions(+), 107 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 2c7d88c..b18df5c 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -5,7 +5,7 @@ Name: kexec-tools Version: 2.0.28 -Release: 7%{?dist} +Release: 8%{?dist} License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -57,28 +57,10 @@ Source109: dracut-early-kdump-module-setup.sh Source200: dracut-fadump-init-fadump.sh Source201: dracut-fadump-module-setup.sh -%ifarch ppc64 ppc64le -Requires(post): servicelog -Recommends: keyutils -%endif -Requires(pre): coreutils sed -Requires: makedumpfile -Requires: dracut >= 058 -Requires: dracut-network >= 058 -Requires: dracut-squash >= 058 -Requires: ethtool -Requires: util-linux -# Needed for UKI support -Recommends: binutils -Recommends: grubby -Recommends: hostname -BuildRequires: make -BuildRequires: systemd-rpm-macros -BuildRequires: automake autoconf libtool - -%ifnarch s390x -Requires: systemd-udev%{?_isa} -%endif +BuildRequires: automake +BuildRequires: autoconf +BuildRequires: libtool +BuildRequires: gcc #START INSERT @@ -152,6 +134,40 @@ makedumpfile is a tool to compress and filter out unneeded data from kernel dumps to reduce its file size. It is typically used with the kdump mechanism. +%package -n kdump-utils +Version: 1.0.42 +License: GPL-2.0-only AND LGPL-2.1-or-later +Summary: Kernel crash dump collection utilities + +%ifarch ppc64 ppc64le +Requires(post): servicelog +Recommends: keyutils +%endif +Requires(pre): coreutils +Requires(pre): sed +Requires: kexec-tools >= 2.0.28-8 +Requires: makedumpfile +Requires: dracut >= 058 +Requires: dracut-network >= 058 +Requires: dracut-squash >= 058 +Requires: ethtool +Requires: util-linux +# Needed for UKI support +Recommends: binutils +Recommends: grubby +Recommends: hostname +BuildRequires: systemd-rpm-macros + +%ifnarch s390x +Requires: systemd-udev%{?_isa} +%endif +%description -n kdump-utils +kdump-utils is responsible for collecting the crash kernel dump. It builds and +loads the kdump initramfs so when a kernel crashes, the system will boot the +kdump kernel and initramfs to save the collected crash kernel dump to specified +target. + + %prep %setup -q @@ -180,6 +196,9 @@ autoreconf %endif --sbindir=/usr/sbin rm -f kexec-tools.spec.in +make + +# kdump-utils # setup the docs cp %{SOURCE10} . cp %{SOURCE11} . @@ -193,7 +212,6 @@ cp %{SOURCE38} . %{SOURCE3} %{_target_cpu} > kdump.sysconfig %{SOURCE4} %{_target_cpu} > kdump.conf -make # makedumpfile make -C eppic-%{eppic_ver}/libeppic @@ -202,93 +220,76 @@ make -C makedumpfile-%{mkdf_ver} LDFLAGS="$LDFLAGS -I../eppic-%{eppic_ver}/libep %install -mkdir -p -m755 $RPM_BUILD_ROOT/usr/sbin -mkdir -p -m755 $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig -mkdir -p -m755 $RPM_BUILD_ROOT%{_sysconfdir}/kdump -mkdir -p -m755 $RPM_BUILD_ROOT%{_sysconfdir}/kdump/pre.d -mkdir -p -m755 $RPM_BUILD_ROOT%{_sysconfdir}/kdump/post.d -mkdir -p -m755 $RPM_BUILD_ROOT%{_localstatedir}/crash -mkdir -p -m755 $RPM_BUILD_ROOT%{_mandir}/man8/ -mkdir -p -m755 $RPM_BUILD_ROOT%{_mandir}/man5/ -mkdir -p -m755 $RPM_BUILD_ROOT%{_docdir} -mkdir -p -m755 $RPM_BUILD_ROOT%{_datadir}/kdump -mkdir -p -m755 $RPM_BUILD_ROOT%{_udevrulesdir} -mkdir -p $RPM_BUILD_ROOT%{_unitdir} -mkdir -p -m755 $RPM_BUILD_ROOT%{_bindir} -mkdir -p -m755 $RPM_BUILD_ROOT%{_libdir} -mkdir -p -m755 $RPM_BUILD_ROOT%{_prefix}/lib/kdump -mkdir -p -m755 $RPM_BUILD_ROOT%{_sharedstatedir}/kdump -install -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/kdumpctl +%make_install +rm -f %{buildroot}/%{_libdir}/kexec-tools/kexec_test -install -m 755 build/sbin/kexec $RPM_BUILD_ROOT/usr/sbin/kexec -install -m 755 build/sbin/vmcore-dmesg $RPM_BUILD_ROOT/usr/sbin/vmcore-dmesg -install -m 644 build/man/man8/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/ -install -m 644 build/man/man8/vmcore-dmesg.8 $RPM_BUILD_ROOT%{_mandir}/man8/ +# kdump-utils +mkdir -p -m755 %{buildroot}%{_sysconfdir}/kdump/pre.d +mkdir -p -m755 %{buildroot}%{_sysconfdir}/kdump/post.d +mkdir -p -m755 %{buildroot}%{_localstatedir}/crash +mkdir -p -m755 %{buildroot}%{_udevrulesdir} +mkdir -p -m755 %{buildroot}%{_sharedstatedir}/kdump -install -m 755 %{SOURCE7} $RPM_BUILD_ROOT/usr/sbin/mkdumprd -install -m 644 kdump.conf $RPM_BUILD_ROOT%{_sysconfdir}/kdump.conf -install -m 644 kdump.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/kdump -install -m 644 kexec/kexec.8 $RPM_BUILD_ROOT%{_mandir}/man8/kexec.8 -install -m 644 %{SOURCE12} $RPM_BUILD_ROOT%{_mandir}/man8/mkdumprd.8 -install -m 644 %{SOURCE25} $RPM_BUILD_ROOT%{_mandir}/man8/kdumpctl.8 -install -m 755 %{SOURCE20} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib.sh -install -m 755 %{SOURCE23} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-lib-initramfs.sh -install -m 755 %{SOURCE31} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-logger.sh +install -D -m 755 %{SOURCE1} %{buildroot}%{_bindir}/kdumpctl +install -D -m 755 %{SOURCE7} %{buildroot}%{_sbindir}/mkdumprd +install -D -m 644 kdump.conf %{buildroot}%{_sysconfdir}/kdump.conf +install -D -m 644 kdump.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/kdump +install -D -m 644 %{SOURCE12} %{SOURCE25} -t %{buildroot}%{_mandir}/man8 +install -D -m 755 %{SOURCE20} %{SOURCE23} %{SOURCE31} -t %{buildroot}%{_prefix}/lib/kdump %ifarch ppc64 ppc64le -install -m 755 %{SOURCE32} $RPM_BUILD_ROOT/usr/sbin/mkfadumprd -install -m 755 %{SOURCE35} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-migrate-action.sh -install -m 755 %{SOURCE36} $RPM_BUILD_ROOT%{_prefix}/lib/kdump/kdump-restart.sh +install -m 755 %{SOURCE32} %{buildroot}%{_sbindir}/mkfadumprd +install -m 755 %{SOURCE35} %{SOURCE36} -t %{buildroot}%{_prefix}/lib/kdump %endif %ifnarch s390x -install -m 755 %{SOURCE28} $RPM_BUILD_ROOT%{_udevrulesdir}/../kdump-udev-throttler +install -m 755 %{SOURCE28} %{buildroot}%{_udevrulesdir}/../kdump-udev-throttler %endif %ifnarch s390x ppc64 ppc64le # For s390x the ELF header is created in the kdump kernel and therefore kexec # udev rules are not required -install -m 644 %{SOURCE13} $RPM_BUILD_ROOT%{_udevrulesdir}/98-kexec.rules +install -m 644 %{SOURCE13} %{buildroot}%{_udevrulesdir}/98-kexec.rules %endif %ifarch ppc64 ppc64le -install -m 644 %{SOURCE14} $RPM_BUILD_ROOT%{_udevrulesdir}/98-kexec.rules -install -m 755 -D %{SOURCE37} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-fadump.install +install -m 644 %{SOURCE14} %{buildroot}%{_udevrulesdir}/98-kexec.rules +install -m 755 -D %{SOURCE37} %{buildroot}%{_prefix}/lib/kernel/install.d/60-fadump.install +%endif +install -D -m 644 %{SOURCE15} %{buildroot}%{_mandir}/man5/kdump.conf.5 +install -D -m 644 %{SOURCE16} %{buildroot}%{_unitdir}/kdump.service +install -m 755 -D %{SOURCE22} %{buildroot}%{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh +install -m 755 -D %{SOURCE30} %{buildroot}%{_prefix}/lib/kernel/install.d/60-kdump.install +install -m 755 -D %{SOURCE33} %{buildroot}%{_prefix}/lib/kernel/install.d/92-crashkernel.install + +%define dracutdir %{_prefix}/lib/dracut/modules.d + +# deal with dracut modules +mkdir -p -m755 %{buildroot}/%{dracutdir}/99kdumpbase +install -m 755 %{SOURCE100} %{buildroot}/%{dracutdir}/99kdumpbase/kdump.sh +install -m 755 %{SOURCE101} %{buildroot}/%{dracutdir}/99kdumpbase/module-setup.sh +install -m 755 %{SOURCE102} %{buildroot}/%{dracutdir}/99kdumpbase/monitor_dd_progress.sh +install -m 644 %{SOURCE104} %{buildroot}/%{dracutdir}/99kdumpbase/kdump-emergency.service +install -m 644 %{SOURCE106} %{buildroot}/%{dracutdir}/99kdumpbase/kdump-capture.service +install -m 644 %{SOURCE107} %{buildroot}/%{dracutdir}/99kdumpbase/kdump-emergency.target + +mkdir -p -m755 %{buildroot}/%{dracutdir}/99earlykdump +install -m 755 %{SOURCE108} %{buildroot}/%{dracutdir}/99earlykdump/kdump.sh +install -m 755 %{SOURCE109} %{buildroot}/%{dracutdir}/99earlykdump/kdump-module-setup.sh + +%ifarch ppc64 ppc64le +mkdir -p -m755 %{buildroot}/%{dracutdir}/99zz-fadumpinit +install -m 755 %{SOURCE200} %{buildroot}/%{dracutdir}/99zz-fadumpinit/init-fadump.sh +install -m 755 %{SOURCE201} %{buildroot}/%{dracutdir}/99zz-fadumpinit/module-setup.sh %endif -install -m 644 %{SOURCE15} $RPM_BUILD_ROOT%{_mandir}/man5/kdump.conf.5 -install -m 644 %{SOURCE16} $RPM_BUILD_ROOT%{_unitdir}/kdump.service -install -m 755 -D %{SOURCE22} $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh -install -m 755 -D %{SOURCE30} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/60-kdump.install -install -m 755 -D %{SOURCE33} $RPM_BUILD_ROOT%{_prefix}/lib/kernel/install.d/92-crashkernel.install # makedumpfile install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.8 $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8 install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf.5 $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5 install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf $RPM_BUILD_ROOT/%{_sysconfdir}/makedumpfile.conf.sample -install -m 755 makedumpfile-%{mkdf_ver}/eppic_makedumpfile.so $RPM_BUILD_ROOT/%{_libdir}/eppic_makedumpfile.so +install -m 755 -D makedumpfile-%{mkdf_ver}/eppic_makedumpfile.so $RPM_BUILD_ROOT/%{_libdir}/eppic_makedumpfile.so mkdir -p $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ install -m 644 makedumpfile-%{mkdf_ver}/eppic_scripts/* $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ -%define dracutdir %{_prefix}/lib/dracut/modules.d -%define remove_prefix() %(echo -n %2|sed 's/.*%1-//g') -# deal with dracut modules -mkdir -p -m755 $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase -install -m 755 %{SOURCE100} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE100}} -install -m 755 %{SOURCE101} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE101}} -install -m 644 %{SOURCE102} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE102}} -install -m 644 %{SOURCE104} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE104}} -install -m 644 %{SOURCE106} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE106}} -install -m 644 %{SOURCE107} $RPM_BUILD_ROOT/%{dracutdir}/99kdumpbase/%{remove_prefix dracut %{SOURCE107}} - -mkdir -p -m755 $RPM_BUILD_ROOT/%{dracutdir}/99earlykdump -install -m 755 %{SOURCE108} $RPM_BUILD_ROOT/%{dracutdir}/99earlykdump/%{remove_prefix dracut %{SOURCE108}} -install -m 755 %{SOURCE109} $RPM_BUILD_ROOT/%{dracutdir}/99earlykdump/%{remove_prefix dracut-early-kdump %{SOURCE109}} - -%ifarch ppc64 ppc64le -mkdir -p -m755 $RPM_BUILD_ROOT/%{dracutdir}/99zz-fadumpinit -install -m 755 %{SOURCE200} $RPM_BUILD_ROOT/%{dracutdir}/99zz-fadumpinit/%{remove_prefix dracut-fadump %{SOURCE200}} -install -m 755 %{SOURCE201} $RPM_BUILD_ROOT/%{dracutdir}/99zz-fadumpinit/%{remove_prefix dracut-fadump %{SOURCE201}} -%endif - -%post +%post -n kdump-utils # Initial installation %systemd_post kdump.service @@ -301,20 +302,20 @@ servicelog_notify --add --command=/usr/lib/kdump/kdump-migrate-action.sh --match : -%postun +%postun -n kdump-utils %systemd_postun_with_restart kdump.service -%preun +%preun -n kdump-utils %ifarch ppc64 ppc64le servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh >/dev/null %endif %systemd_preun kdump.service -%triggerin -- kernel-kdump +%triggerin -n kdump-utils -- kernel-kdump touch %{_sysconfdir}/kdump.conf -%triggerpostun -- kernel kernel-xen kernel-debug kernel-PAE kernel-kdump +%triggerpostun -n kdump-utils -- kernel kernel-xen kernel-debug kernel-PAE kernel-kdump # List out the initrds here, strip out version nubmers # and search for corresponding kernel installs, if a kernel # is not found, remove the corresponding kdump initrd @@ -332,7 +333,7 @@ do fi done -%posttrans +%posttrans -n kdump-utils # Try to reset kernel crashkernel value to new default value or set up # crasherkernel value for new install # @@ -347,20 +348,26 @@ fi %files -/usr/sbin/kexec +%{_sbindir}/kexec +%{_mandir}/man8/kexec.8* +%{_sbindir}/vmcore-dmesg +%{_mandir}/man8/vmcore-dmesg.8* +%doc News +%license COPYING +%doc TODO + +%files -n kdump-utils %ifarch ppc64 ppc64le -/usr/sbin/mkfadumprd +%{_sbindir}/mkfadumprd %{_prefix}/lib/kernel/install.d/60-fadump.install %endif -/usr/sbin/mkdumprd -/usr/sbin/vmcore-dmesg +%{_sbindir}/mkdumprd %{_bindir}/* -%{_datadir}/kdump %{_prefix}/lib/kdump %config(noreplace,missingok) %{_sysconfdir}/sysconfig/kdump %config(noreplace,missingok) %verify(not mtime) %{_sysconfdir}/kdump.conf %ifnarch s390x -%config %{_udevrulesdir} +%{_udevrulesdir} %{_udevrulesdir}/../kdump-udev-throttler %endif %{dracutdir}/* @@ -369,18 +376,14 @@ fi %dir %{_sysconfdir}/kdump/pre.d %dir %{_sysconfdir}/kdump/post.d %dir %{_sharedstatedir}/kdump -%{_mandir}/man8/kdumpctl.8.gz -%{_mandir}/man8/kexec.8.gz -%{_mandir}/man8/mkdumprd.8.gz -%{_mandir}/man8/vmcore-dmesg.8.gz -%{_mandir}/man5/kdump.conf.5.gz +%{_mandir}/man8/kdumpctl.8* +%{_mandir}/man8/mkdumprd.8* +%{_mandir}/man5/kdump.conf.5* %{_unitdir}/kdump.service %{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh %{_prefix}/lib/kernel/install.d/60-kdump.install %{_prefix}/lib/kernel/install.d/92-crashkernel.install -%doc News %license COPYING -%doc TODO %doc kexec-kdump-howto.txt %doc early-kdump-howto.txt %doc fadump-howto.txt @@ -401,6 +404,9 @@ fi %changelog +* Tue Mar 19 2024 Coiby Xu - 2.0.28-8 +- Add a kdump-utils subpackage + * Sun Apr 07 2024 Coiby Xu - 2.0.28-7 - Release 2.0.28-7 From 5fe098fec8eb19a942a608f19324601066c0467d Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 29 Feb 2024 11:05:14 +0800 Subject: [PATCH 422/454] Don't systemctl preset kdump when updating kexec-tools to kdump-utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When an old version of kexec-tools gets replaced by kdump-utils, "%systemd_post" will be executed in the post scriptlet which has the purpose to "systemctl preset kdump" for freshly installed kexec-tools. But in the case of kdump-utils replacing kexec-tools, it is not needed so skip this case. Signed-off-by: Coiby Xu Suggested-by: Zbigniew Jędrzejewski-Szmek Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index b18df5c..c8f89f0 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -290,8 +290,16 @@ install -m 644 makedumpfile-%{mkdf_ver}/eppic_scripts/* $RPM_BUILD_ROOT/usr/shar %post -n kdump-utils -# Initial installation -%systemd_post kdump.service +# don't try to systemctl preset the kdump service for old kexec-tools +# +# when the old kexec-tools gets removed, this trigger will be excuted to +# create a file. So later the posttrans scriptlet will know there is no need to +# systemctl preset the kdump service. +# This solution can be dropped in F41 when we assume no users will use old +# version of kexec-tools. +%define kexec_tools_no_preset %{_localstatedir}/lib/rpm-state/kexec-tools.no-preset +%triggerun -- kexec-tools +touch %{kexec_tools_no_preset} touch /etc/kdump.conf @@ -334,6 +342,14 @@ do done %posttrans -n kdump-utils +# don't try to systemctl preset the kdump service for old kexec-tools +if [[ -f %{kexec_tools_no_preset} ]]; then + # this if branch can be removed in F41 when we assume no users will use the old kexec-tools + rm %{kexec_tools_no_preset} +else + # Initial installation + %systemd_post kdump.service +fi # Try to reset kernel crashkernel value to new default value or set up # crasherkernel value for new install # From c7683d8aabdbbbaaefdeee4a3e6c35482dca48c7 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Thu, 29 Feb 2024 11:18:00 +0800 Subject: [PATCH 423/454] Don't disrupt current kdump users Majority of current kexec-tools users have installed kexec-tools out of the need for the kdump feature. To ensure a smooth transition, add kdump-utils as weak dependency. If users only want to use kexec-tools, they can uninstall kdump-utils. Signed-off-by: Coiby Xu Suggested-by: Carl George Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/kexec-tools.spec b/kexec-tools.spec index c8f89f0..2dfe7fb 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -10,6 +10,7 @@ License: GPL-2.0-only Summary: The kexec/kdump userspace component Source0: http://kernel.org/pub/linux/utils/kernel/kexec/%{name}-%{version}.tar.xz +Recommends: kdump-utils Source1: kdumpctl Source3: gen-kdump-sysconfig.sh Source4: gen-kdump-conf.sh From a442b4e51222114cbed354f298fce8f37c88cc75 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 26 Mar 2024 19:08:00 +0800 Subject: [PATCH 424/454] Remove unused scriptlets Suggested-by: Philipp Rudo Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 2dfe7fb..a5d8bba 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -320,27 +320,6 @@ servicelog_notify --remove --command=/usr/lib/kdump/kdump-migrate-action.sh >/de %endif %systemd_preun kdump.service -%triggerin -n kdump-utils -- kernel-kdump -touch %{_sysconfdir}/kdump.conf - - -%triggerpostun -n kdump-utils -- kernel kernel-xen kernel-debug kernel-PAE kernel-kdump -# List out the initrds here, strip out version nubmers -# and search for corresponding kernel installs, if a kernel -# is not found, remove the corresponding kdump initrd - - -IMGDIR=/boot -for i in `ls $IMGDIR/initramfs*kdump.img 2>/dev/null` -do - KDVER=`echo $i | sed -e's/^.*initramfs-//' -e's/kdump.*$//'` - if [ ! -e $IMGDIR/vmlinuz-$KDVER ] - then - # We have found an initrd with no corresponding kernel - # so we should be able to remove it - rm -f $i - fi -done %posttrans -n kdump-utils # don't try to systemctl preset the kdump service for old kexec-tools From f7bd239656269ea777454fe6c541aa0decaa4545 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 9 Apr 2024 07:26:13 +0800 Subject: [PATCH 425/454] makedumpfile: re-use source Makefile's install logic Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index a5d8bba..ce3a97b 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -281,14 +281,12 @@ install -m 755 %{SOURCE201} %{buildroot}/%{dracutdir}/99zz-fadumpinit/module-set %endif # makedumpfile -install -m 755 makedumpfile-%{mkdf_ver}/makedumpfile $RPM_BUILD_ROOT/usr/sbin/makedumpfile -install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.8 $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8 -install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf.5 $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5 -install -m 644 makedumpfile-%{mkdf_ver}/makedumpfile.conf $RPM_BUILD_ROOT/%{_sysconfdir}/makedumpfile.conf.sample -install -m 755 -D makedumpfile-%{mkdf_ver}/eppic_makedumpfile.so $RPM_BUILD_ROOT/%{_libdir}/eppic_makedumpfile.so -mkdir -p $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ -install -m 644 makedumpfile-%{mkdf_ver}/eppic_scripts/* $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ +make DESTDIR=%{buildroot} -C makedumpfile-%{mkdf_ver} install +install -m 644 -D makedumpfile-%{mkdf_ver}/makedumpfile.conf %{buildroot}/%{_sysconfdir}/makedumpfile.conf.sample +rm %{buildroot}/%{_sbindir}/makedumpfile-R.pl + +install -m 755 -D makedumpfile-%{mkdf_ver}/eppic_makedumpfile.so %{buildroot}/%{_libdir}/eppic_makedumpfile.so %post -n kdump-utils # don't try to systemctl preset the kdump service for old kexec-tools @@ -392,8 +390,8 @@ fi %files -n makedumpfile %license makedumpfile-%{mkdf_ver}/COPYING %{_sbindir}/makedumpfile -%{_mandir}/man5/makedumpfile.conf.5.gz -%{_mandir}/man8/makedumpfile.8.gz +%{_mandir}/man5/makedumpfile.conf.5.* +%{_mandir}/man8/makedumpfile.8.* %{_sysconfdir}/makedumpfile.conf.sample %{_libdir}/eppic_makedumpfile.so %{_datadir}/makedumpfile/ From 3fa5df9a684f63e9aa5b42a4c9de538d3be457ed Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Mon, 8 Apr 2024 13:17:23 +0800 Subject: [PATCH 426/454] Add URL for kexec-tools and kump-utils Suggested-by: Dave Young Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kexec-tools.spec b/kexec-tools.spec index ce3a97b..f1d4ff9 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -6,6 +6,7 @@ Name: kexec-tools Version: 2.0.28 Release: 8%{?dist} +URL: https://kernel.org/pub/linux/utils/kernel/kexec License: GPL-2.0-only Summary: The kexec/kdump userspace component @@ -138,6 +139,7 @@ dumps to reduce its file size. It is typically used with the kdump mechanism. %package -n kdump-utils Version: 1.0.42 License: GPL-2.0-only AND LGPL-2.1-or-later +URL: https://github.com/rhkdump/kdump-utils Summary: Kernel crash dump collection utilities %ifarch ppc64 ppc64le From fe372afddde500249cd02fc3f152a164cfed321f Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 1 Mar 2024 17:37:24 +0800 Subject: [PATCH 427/454] Upstream kdump-utils This patch upstreams the to-be-split-out kdump-utils to https://github.com/rhkdump/kdump-utils. And it also simplify the .spec file by putting the installation logic into a Makefile. Cc: Philipp Rudo Cc: Carl George Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- COPYING | 339 +++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 83 ++++++++++++ kexec-tools.spec | 139 +++---------------- 3 files changed, 438 insertions(+), 123 deletions(-) create mode 100644 COPYING create mode 100644 Makefile diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e1a511c --- /dev/null +++ b/Makefile @@ -0,0 +1,83 @@ +prefix ?= /usr +libdir ?= ${prefix}/lib +datadir ?= ${prefix}/share +pkglibdir ?= ${libdir}/kdump +sysconfdir ?= /etc +bindir ?= ${prefix}/bin +sbindir ?= ${prefix}/sbin +mandir ?= ${prefix}/share/man +localstatedir ?= /var +sharedstatedir ?= /var/lib +udevrulesdir ?= ${libdir}/udev/rules.d +systemdsystemunitdir ?= ${libdir}/systemd/system/ +ARCH ?= $(shell uname -m) +dracutmoddir = $(DESTDIR)${libdir}/dracut/modules.d +kdumpbasemoddir = $(dracutmoddir)/99kdumpbase + +dracut-modules: + mkdir -p $(dracutmoddir) + mkdir -p -m755 $(kdumpbasemoddir) + + install -m 755 dracut-kdump.sh $(kdumpbasemoddir)/kdump.sh + install -m 755 dracut-module-setup.sh $(kdumpbasemoddir)/module-setup.sh + install -m 755 dracut-monitor_dd_progress.sh $(kdumpbasemoddir)/monitor_dd_progress.sh + install -m 644 dracut-kdump-emergency.service $(kdumpbasemoddir)/kdump-emergency.service + install -m 644 dracut-kdump-capture.service $(kdumpbasemoddir)/kdump-capture.service + install -m 644 dracut-kdump-emergency.target $(kdumpbasemoddir)/kdump-emergency.target + + mkdir -p -m755 $(dracutmoddir)/99earlykdump + install -m 755 dracut-early-kdump.sh $(dracutmoddir)/99earlykdump/kdump.sh + install -m 755 dracut-early-kdump-module-setup.sh $(dracutmoddir)/99earlykdump/kdump-module-setup.sh + +ifeq ($(ARCH), $(filter ppc64le ppc64,$(ARCH))) + mkdir -p -m755 $(dracutmoddir)/99zz-fadumpinit + install -m 755 dracut-fadump-init-fadump.sh $(dracutmoddir)/99zz-fadumpinit/init-fadump.sh + install -m 755 dracut-fadump-module-setup.sh $(dracutmoddir)/99zz-fadumpinit/module-setup.sh +endif + +kdump-conf: gen-kdump-conf.sh + ./gen-kdump-conf.sh $(ARCH) > kdump.conf + +kdump-sysconfig: gen-kdump-sysconfig.sh + ./gen-kdump-sysconfig.sh $(ARCH) > kdump.sysconfig + +manpages: + install -D -m 644 mkdumprd.8 kdumpctl.8 -t $(DESTDIR)$(mandir)/man8 + install -D -m 644 kdump.conf.5 $(DESTDIR)$(mandir)/man5/kdump.conf.5 + +install: dracut-modules kdump-conf kdump-sysconfig manpages + mkdir -p $(DESTDIR)$(pkglibdir) + mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/pre.d + mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/post.d + mkdir -p -m755 $(DESTDIR)$(localstatedir)/crash + mkdir -p -m755 $(DESTDIR)$(udevrulesdir) + mkdir -p -m755 $(DESTDIR)$(sharedstatedir)/kdump + mkdir -p -m755 $(DESTDIR)$(libdir)/kernel/install.d/ + + install -D -m 755 kdumpctl $(DESTDIR)$(bindir)/kdumpctl + install -D -m 755 mkdumprd $(DESTDIR)$(sbindir)/mkdumprd + install -D -m 644 kdump.conf $(DESTDIR)$(sysconfdir) + install -D -m 644 kdump.sysconfig $(DESTDIR)$(sysconfdir)/sysconfig/kdump + install -D -m 755 kdump-lib.sh kdump-lib-initramfs.sh kdump-logger.sh -t $(DESTDIR)$(pkglibdir) + +ifeq ($(ARCH), $(filter ppc64le ppc64,$(ARCH))) + install -m 755 mkfadumprd $(DESTDIR)$(sbindir) + install -m 755 kdump-migrate-action.sh kdump-restart.sh -t $(DESTDIR)$(pkglibdir) + install -m 755 60-fadump.install $(DESTDIR)$(libdir)/kernel/install.d/ +endif + +ifneq ($(ARCH),s390x) + install -m 755 kdump-udev-throttler $(DESTDIR)$(udevrulesdir)/../kdump-udev-throttler + # For s390x the ELF header is created in the kdump kernel and therefore kexec + # udev rules are not required +ifeq ($(ARCH), $(filter ppc64le ppc64,$(ARCH))) + install -m 644 98-kexec.rules.ppc64 $(DESTDIR)$(udevrulesdir)/98-kexec.rules +else + install -m 644 98-kexec.rules $(DESTDIR)$(udevrulesdir)/98-kexec.rules +endif +endif + + install -D -m 644 kdump.service $(DESTDIR)$(systemdsystemunitdir)/kdump.service + install -m 755 -D kdump-dep-generator.sh $(DESTDIR)$(libdir)/systemd/system-generators/kdump-dep-generator.sh + install -m 755 60-kdump.install $(DESTDIR)$(libdir)/kernel/install.d/ + install -m 755 92-crashkernel.install $(DESTDIR)$(libdir)/kernel/install.d/ diff --git a/kexec-tools.spec b/kexec-tools.spec index f1d4ff9..cf88e5b 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -1,6 +1,7 @@ %global eppic_ver e8844d3793471163ae4a56d8f95897be9e5bd554 %global eppic_shortver %(c=%{eppic_ver}; echo ${c:0:7}) %global mkdf_ver 1.7.4 +%global kdump_utils_ver 1.0.42 %global mkdf_shortver %(c=%{mkdf_ver}; echo ${c:0:7}) Name: kexec-tools @@ -12,52 +13,9 @@ Summary: The kexec/kdump userspace component Source0: http://kernel.org/pub/linux/utils/kernel/kexec/%{name}-%{version}.tar.xz Recommends: kdump-utils -Source1: kdumpctl -Source3: gen-kdump-sysconfig.sh -Source4: gen-kdump-conf.sh -Source7: mkdumprd +Source1: https://github.com/rhkdump/kdump-utils/archive/v%{kdump_utils_ver}/kdump-utils-%{kdump_utils_ver}.tar.gz Source9: https://github.com/makedumpfile/makedumpfile/archive/%{mkdf_ver}/makedumpfile-%{mkdf_shortver}.tar.gz -Source10: kexec-kdump-howto.txt -Source11: fadump-howto.txt -Source12: mkdumprd.8 -Source13: 98-kexec.rules -Source14: 98-kexec.rules.ppc64 -Source15: kdump.conf.5 -Source16: kdump.service Source19: https://github.com/lucchouina/eppic/archive/%{eppic_ver}/eppic-%{eppic_shortver}.tar.gz -Source20: kdump-lib.sh -Source21: kdump-in-cluster-environment.txt -Source22: kdump-dep-generator.sh -Source23: kdump-lib-initramfs.sh -Source25: kdumpctl.8 -Source26: live-image-kdump-howto.txt -Source27: early-kdump-howto.txt -Source28: kdump-udev-throttler -Source30: 60-kdump.install -Source31: kdump-logger.sh -Source32: mkfadumprd -Source33: 92-crashkernel.install -Source34: crashkernel-howto.txt -Source35: kdump-migrate-action.sh -Source36: kdump-restart.sh -Source37: 60-fadump.install -Source38: supported-kdump-targets.txt - -####################################### -# These are sources for mkdumpramfs -# Which is currently in development -####################################### -Source100: dracut-kdump.sh -Source101: dracut-module-setup.sh -Source102: dracut-monitor_dd_progress -Source104: dracut-kdump-emergency.service -Source106: dracut-kdump-capture.service -Source107: dracut-kdump-emergency.target -Source108: dracut-early-kdump.sh -Source109: dracut-early-kdump-module-setup.sh - -Source200: dracut-fadump-init-fadump.sh -Source201: dracut-fadump-module-setup.sh BuildRequires: automake BuildRequires: autoconf @@ -174,6 +132,8 @@ target. %prep %setup -q +tar -z -x -v -f %{SOURCE1} + mkdir -p -m755 kcp tar -z -x -v -f %{SOURCE9} tar -z -x -v -f %{SOURCE19} @@ -201,21 +161,6 @@ autoreconf rm -f kexec-tools.spec.in make -# kdump-utils -# setup the docs -cp %{SOURCE10} . -cp %{SOURCE11} . -cp %{SOURCE21} . -cp %{SOURCE26} . -cp %{SOURCE27} . -cp %{SOURCE34} . -cp %{SOURCE38} . - -# Generate sysconfig file -%{SOURCE3} %{_target_cpu} > kdump.sysconfig -%{SOURCE4} %{_target_cpu} > kdump.conf - - # makedumpfile make -C eppic-%{eppic_ver}/libeppic make -C makedumpfile-%{mkdf_ver} LINKTYPE=dynamic USELZO=on USESNAPPY=on USEZSTD=on @@ -227,60 +172,8 @@ make -C makedumpfile-%{mkdf_ver} LDFLAGS="$LDFLAGS -I../eppic-%{eppic_ver}/libep rm -f %{buildroot}/%{_libdir}/kexec-tools/kexec_test # kdump-utils -mkdir -p -m755 %{buildroot}%{_sysconfdir}/kdump/pre.d -mkdir -p -m755 %{buildroot}%{_sysconfdir}/kdump/post.d -mkdir -p -m755 %{buildroot}%{_localstatedir}/crash -mkdir -p -m755 %{buildroot}%{_udevrulesdir} -mkdir -p -m755 %{buildroot}%{_sharedstatedir}/kdump - -install -D -m 755 %{SOURCE1} %{buildroot}%{_bindir}/kdumpctl -install -D -m 755 %{SOURCE7} %{buildroot}%{_sbindir}/mkdumprd -install -D -m 644 kdump.conf %{buildroot}%{_sysconfdir}/kdump.conf -install -D -m 644 kdump.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/kdump -install -D -m 644 %{SOURCE12} %{SOURCE25} -t %{buildroot}%{_mandir}/man8 -install -D -m 755 %{SOURCE20} %{SOURCE23} %{SOURCE31} -t %{buildroot}%{_prefix}/lib/kdump -%ifarch ppc64 ppc64le -install -m 755 %{SOURCE32} %{buildroot}%{_sbindir}/mkfadumprd -install -m 755 %{SOURCE35} %{SOURCE36} -t %{buildroot}%{_prefix}/lib/kdump -%endif -%ifnarch s390x -install -m 755 %{SOURCE28} %{buildroot}%{_udevrulesdir}/../kdump-udev-throttler -%endif -%ifnarch s390x ppc64 ppc64le -# For s390x the ELF header is created in the kdump kernel and therefore kexec -# udev rules are not required -install -m 644 %{SOURCE13} %{buildroot}%{_udevrulesdir}/98-kexec.rules -%endif -%ifarch ppc64 ppc64le -install -m 644 %{SOURCE14} %{buildroot}%{_udevrulesdir}/98-kexec.rules -install -m 755 -D %{SOURCE37} %{buildroot}%{_prefix}/lib/kernel/install.d/60-fadump.install -%endif -install -D -m 644 %{SOURCE15} %{buildroot}%{_mandir}/man5/kdump.conf.5 -install -D -m 644 %{SOURCE16} %{buildroot}%{_unitdir}/kdump.service -install -m 755 -D %{SOURCE22} %{buildroot}%{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh -install -m 755 -D %{SOURCE30} %{buildroot}%{_prefix}/lib/kernel/install.d/60-kdump.install -install -m 755 -D %{SOURCE33} %{buildroot}%{_prefix}/lib/kernel/install.d/92-crashkernel.install - -%define dracutdir %{_prefix}/lib/dracut/modules.d - -# deal with dracut modules -mkdir -p -m755 %{buildroot}/%{dracutdir}/99kdumpbase -install -m 755 %{SOURCE100} %{buildroot}/%{dracutdir}/99kdumpbase/kdump.sh -install -m 755 %{SOURCE101} %{buildroot}/%{dracutdir}/99kdumpbase/module-setup.sh -install -m 755 %{SOURCE102} %{buildroot}/%{dracutdir}/99kdumpbase/monitor_dd_progress.sh -install -m 644 %{SOURCE104} %{buildroot}/%{dracutdir}/99kdumpbase/kdump-emergency.service -install -m 644 %{SOURCE106} %{buildroot}/%{dracutdir}/99kdumpbase/kdump-capture.service -install -m 644 %{SOURCE107} %{buildroot}/%{dracutdir}/99kdumpbase/kdump-emergency.target - -mkdir -p -m755 %{buildroot}/%{dracutdir}/99earlykdump -install -m 755 %{SOURCE108} %{buildroot}/%{dracutdir}/99earlykdump/kdump.sh -install -m 755 %{SOURCE109} %{buildroot}/%{dracutdir}/99earlykdump/kdump-module-setup.sh - -%ifarch ppc64 ppc64le -mkdir -p -m755 %{buildroot}/%{dracutdir}/99zz-fadumpinit -install -m 755 %{SOURCE200} %{buildroot}/%{dracutdir}/99zz-fadumpinit/init-fadump.sh -install -m 755 %{SOURCE201} %{buildroot}/%{dracutdir}/99zz-fadumpinit/module-setup.sh -%endif +%define kdump_utils_dir kdump-utils-%{kdump_utils_ver} +make DESTDIR=%{buildroot} -C %kdump_utils_dir install # makedumpfile @@ -366,7 +259,7 @@ fi %{_udevrulesdir} %{_udevrulesdir}/../kdump-udev-throttler %endif -%{dracutdir}/* +%{_prefix}/lib/dracut/modules.d/* %dir %{_localstatedir}/crash %dir %{_sysconfdir}/kdump %dir %{_sysconfdir}/kdump/pre.d @@ -379,14 +272,14 @@ fi %{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh %{_prefix}/lib/kernel/install.d/60-kdump.install %{_prefix}/lib/kernel/install.d/92-crashkernel.install -%license COPYING -%doc kexec-kdump-howto.txt -%doc early-kdump-howto.txt -%doc fadump-howto.txt -%doc kdump-in-cluster-environment.txt -%doc live-image-kdump-howto.txt -%doc crashkernel-howto.txt -%doc supported-kdump-targets.txt +%license %kdump_utils_dir/COPYING +%doc %kdump_utils_dir/kexec-kdump-howto.txt +%doc %kdump_utils_dir/early-kdump-howto.txt +%doc %kdump_utils_dir/fadump-howto.txt +%doc %kdump_utils_dir/kdump-in-cluster-environment.txt +%doc %kdump_utils_dir/live-image-kdump-howto.txt +%doc %kdump_utils_dir/crashkernel-howto.txt +%doc %kdump_utils_dir/supported-kdump-targets.txt %files -n makedumpfile @@ -400,7 +293,7 @@ fi %changelog -* Tue Mar 19 2024 Coiby Xu - 2.0.28-8 +* Tue Apr 09 2024 Coiby Xu - 2.0.28-8 - Add a kdump-utils subpackage * Sun Apr 07 2024 Coiby Xu - 2.0.28-7 From a5c17afe7e871f7a2593d04b97e8e77fb434642c Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Fri, 12 Jan 2024 20:00:53 +0800 Subject: [PATCH 428/454] Fix potential-bashisms in monitor_dd_progress As suggested by Carl [1], > /usr/lib/dracut/modules.d/99kdumpbase/monitor_dd_progress has some > inconsistencies with other scripts in that directory. It is missing the > .sh extension and is not executable. The latter is resulting in an > rpmlint error. [1] https://bugzilla.redhat.com/show_bug.cgi?id=2239566#c2 Suggested-by: Carl George Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- dracut-kdump.sh | 2 +- dracut-module-setup.sh | 3 +-- dracut-monitor_dd_progress => dracut-monitor_dd_progress.sh | 0 3 files changed, 2 insertions(+), 3 deletions(-) rename dracut-monitor_dd_progress => dracut-monitor_dd_progress.sh (100%) diff --git a/dracut-kdump.sh b/dracut-kdump.sh index 1fc2231..7b3ad7a 100755 --- a/dracut-kdump.sh +++ b/dracut-kdump.sh @@ -377,7 +377,7 @@ dump_raw() if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then _src_size=$(stat --format %s /proc/vmcore) _src_size_mb=$((_src_size / 1048576)) - /kdumpscripts/monitor_dd_progress $_src_size_mb & + /kdumpscripts/monitor_dd_progress.sh $_src_size_mb & fi dinfo "saving vmcore" diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index daa6b26..7e1cb9f 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -1020,8 +1020,7 @@ install() { kdump_install_random_seed fi dracut_install -o /etc/adjtime /etc/localtime - inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress" - chmod +x "${initdir}/kdumpscripts/monitor_dd_progress" + inst "$moddir/monitor_dd_progress.sh" "/kdumpscripts/monitor_dd_progress.sh" inst "/bin/dd" "/bin/dd" inst "/bin/tail" "/bin/tail" inst "/bin/date" "/bin/date" diff --git a/dracut-monitor_dd_progress b/dracut-monitor_dd_progress.sh similarity index 100% rename from dracut-monitor_dd_progress rename to dracut-monitor_dd_progress.sh From 2ed88633ade0f1e5523d8097d96df3fde1287ea7 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 9 Apr 2024 09:04:11 +0800 Subject: [PATCH 429/454] kexec-tools: use make_install use consistent build flags %make_install to have the benefits like enabling parallel building automatically. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index cf88e5b..32fddaf 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -159,7 +159,7 @@ autoreconf %endif --sbindir=/usr/sbin rm -f kexec-tools.spec.in -make +%make_build # makedumpfile make -C eppic-%{eppic_ver}/libeppic From b3620b0dbc3e0fb9a92ab5faf34ac3b4e7bb7bd9 Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Tue, 9 Apr 2024 09:25:48 +0800 Subject: [PATCH 430/454] makedumpfile: remove explicit-lib-dependency zlib Fix the following error found by rpmlint, makedumpfile.x86_64: E: explicit-lib-dependency zlib You must let rpm find the library dependencies by itself. Do not put unneeded explicit Requires: tags. Signed-off-by: Coiby Xu Reviewed-by: Philipp Rudo Reviewed-by: Dave Young --- kexec-tools.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/kexec-tools.spec b/kexec-tools.spec index 32fddaf..254d88a 100644 --- a/kexec-tools.spec +++ b/kexec-tools.spec @@ -71,7 +71,6 @@ License: GPL-2.0-only URL: https://github.com/makedumpfile/makedumpfile Conflicts: kexec-tools < 2.0.28-5 -Requires(pre): zlib BuildRequires: make BuildRequires: gcc BuildRequires: zlib-devel From 5be9c9af09b8d883861707f07c344dfbfde993da Mon Sep 17 00:00:00 2001 From: Coiby Xu Date: Sat, 13 Apr 2024 09:59:41 +0800 Subject: [PATCH 431/454] Use upstream source Signed-off-by: Coiby Xu --- 60-fadump.install | 31 - 60-kdump.install | 36 - 92-crashkernel.install | 13 - 98-kexec.rules | 16 - 98-kexec.rules.ppc64 | 22 - COPYING | 339 ------ Makefile | 83 -- crashkernel-howto.txt | 120 -- dracut-early-kdump-module-setup.sh | 65 - dracut-early-kdump.sh | 79 -- dracut-fadump-init-fadump.sh | 48 - dracut-fadump-module-setup.sh | 23 - dracut-kdump-capture.service | 30 - dracut-kdump-emergency.service | 27 - dracut-kdump-emergency.target | 14 - dracut-kdump.sh | 624 ---------- dracut-module-setup.sh | 1083 ----------------- dracut-monitor_dd_progress.sh | 28 - early-kdump-howto.txt | 95 -- fadump-howto.txt | 359 ------ gen-kdump-conf.sh | 225 ---- gen-kdump-sysconfig.sh | 114 -- kdump-dep-generator.sh | 23 - kdump-in-cluster-environment.txt | 91 -- kdump-lib-initramfs.sh | 173 --- kdump-lib.sh | 1117 ------------------ kdump-logger.sh | 355 ------ kdump-migrate-action.sh | 8 - kdump-restart.sh | 8 - kdump-udev-throttler | 42 - kdump.conf.5 | 397 ------- kdump.service | 17 - kdumpctl | 1770 ---------------------------- kdumpctl.8 | 72 -- kexec-kdump-howto.txt | 1055 ----------------- live-image-kdump-howto.txt | 25 - mkdumprd | 417 ------- mkdumprd.8 | 39 - mkfadumprd | 74 -- sources | 1 + supported-kdump-targets.txt | 119 -- zanata-notes.txt | 79 -- 42 files changed, 1 insertion(+), 9355 deletions(-) delete mode 100755 60-fadump.install delete mode 100755 60-kdump.install delete mode 100755 92-crashkernel.install delete mode 100644 98-kexec.rules delete mode 100644 98-kexec.rules.ppc64 delete mode 100644 COPYING delete mode 100644 Makefile delete mode 100644 crashkernel-howto.txt delete mode 100755 dracut-early-kdump-module-setup.sh delete mode 100755 dracut-early-kdump.sh delete mode 100755 dracut-fadump-init-fadump.sh delete mode 100644 dracut-fadump-module-setup.sh delete mode 100644 dracut-kdump-capture.service delete mode 100644 dracut-kdump-emergency.service delete mode 100644 dracut-kdump-emergency.target delete mode 100755 dracut-kdump.sh delete mode 100755 dracut-module-setup.sh delete mode 100644 dracut-monitor_dd_progress.sh delete mode 100644 early-kdump-howto.txt delete mode 100644 fadump-howto.txt delete mode 100755 gen-kdump-conf.sh delete mode 100755 gen-kdump-sysconfig.sh delete mode 100644 kdump-dep-generator.sh delete mode 100644 kdump-in-cluster-environment.txt delete mode 100755 kdump-lib-initramfs.sh delete mode 100755 kdump-lib.sh delete mode 100755 kdump-logger.sh delete mode 100755 kdump-migrate-action.sh delete mode 100644 kdump-restart.sh delete mode 100755 kdump-udev-throttler delete mode 100644 kdump.conf.5 delete mode 100644 kdump.service delete mode 100755 kdumpctl delete mode 100644 kdumpctl.8 delete mode 100644 kexec-kdump-howto.txt delete mode 100644 live-image-kdump-howto.txt delete mode 100644 mkdumprd delete mode 100644 mkdumprd.8 delete mode 100755 mkfadumprd delete mode 100644 supported-kdump-targets.txt delete mode 100644 zanata-notes.txt diff --git a/60-fadump.install b/60-fadump.install deleted file mode 100755 index 75318ff..0000000 --- a/60-fadump.install +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/bash - -COMMAND="$1" -KERNEL_VERSION="$2" - -if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then - exit 0 -fi - -# Currently, fadump is supported only in environments with -# writable /boot directory. -if [[ ! -w "/boot" ]]; then - exit 0 -fi - -FADUMP_INITRD="/boot/.initramfs-${KERNEL_VERSION}.img.default" -FADUMP_INITRD_CHECKSUM="$FADUMP_INITRD.checksum" - -ret=0 -case "$COMMAND" in - add) - # Do nothing, fadump initramfs is strictly host only - # and managed by kdump service - ;; - remove) - rm -f -- "$FADUMP_INITRD" - rm -f -- "$FADUMP_INITRD_CHECKSUM" - ret=$? - ;; -esac -exit $ret diff --git a/60-kdump.install b/60-kdump.install deleted file mode 100755 index 5b0e021..0000000 --- a/60-kdump.install +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/bash - -COMMAND="$1" -KERNEL_VERSION="$2" -KDUMP_INITRD_DIR_ABS="$3" -KERNEL_IMAGE="$4" - -if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then - exit 0 -fi - -if [[ -d "$KDUMP_INITRD_DIR_ABS" ]]; then - KDUMP_INITRD="initrdkdump" -else - # If `KDUMP_BOOTDIR` is not writable, then the kdump - # initrd must have been placed at `/var/lib/kdump` - if [[ ! -w "/boot" ]]; then - KDUMP_INITRD_DIR_ABS="/var/lib/kdump" - else - KDUMP_INITRD_DIR_ABS="/boot" - fi - KDUMP_INITRD="initramfs-${KERNEL_VERSION}kdump.img" -fi - -ret=0 -case "$COMMAND" in - add) - # Do nothing, kdump initramfs is strictly host only - # and managed by kdump service - ;; - remove) - rm -f -- "$KDUMP_INITRD_DIR_ABS/$KDUMP_INITRD" - ret=$? - ;; -esac -exit $ret diff --git a/92-crashkernel.install b/92-crashkernel.install deleted file mode 100755 index 19bd078..0000000 --- a/92-crashkernel.install +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/bash - -COMMAND="$1" -KERNEL_VERSION="$2" -KDUMP_INITRD_DIR_ABS="$3" -KERNEL_IMAGE="$4" - -case "$COMMAND" in -add) - kdumpctl _reset-crashkernel-for-installed_kernel "$KERNEL_VERSION" - exit 0 - ;; -esac diff --git a/98-kexec.rules b/98-kexec.rules deleted file mode 100644 index b73b701..0000000 --- a/98-kexec.rules +++ /dev/null @@ -1,16 +0,0 @@ -SUBSYSTEM=="cpu", ACTION=="add", GOTO="kdump_reload" -SUBSYSTEM=="cpu", ACTION=="remove", GOTO="kdump_reload" -SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload" -SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload" - -GOTO="kdump_reload_end" - -LABEL="kdump_reload" - -# If kdump is not loaded, calling kdump-udev-throttle will end up -# doing nothing, but systemd-run will always generate extra logs for -# each call, so trigger the kdump-udev-throttler only if kdump -# service is active to avoid unnecessary logs -RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'" - -LABEL="kdump_reload_end" diff --git a/98-kexec.rules.ppc64 b/98-kexec.rules.ppc64 deleted file mode 100644 index e9db276..0000000 --- a/98-kexec.rules.ppc64 +++ /dev/null @@ -1,22 +0,0 @@ -SUBSYSTEM=="cpu", ACTION=="online", GOTO="kdump_reload_cpu" -SUBSYSTEM=="memory", ACTION=="online", GOTO="kdump_reload_mem" -SUBSYSTEM=="memory", ACTION=="offline", GOTO="kdump_reload_mem" - -GOTO="kdump_reload_end" - -# If kdump is not loaded, calling kdump-udev-throttle will end up -# doing nothing, but systemd-run will always generate extra logs for -# each call, so trigger the kdump-udev-throttler only if kdump -# service is active to avoid unnecessary logs - -LABEL="kdump_reload_mem" - -RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'" - -GOTO="kdump_reload_end" - -LABEL="kdump_reload_cpu" - -RUN+="/bin/sh -c '/usr/bin/systemctl is-active kdump.service || exit 0; ! test -f /sys/kernel/fadump/enabled || cat /sys/kernel/fadump/enabled | grep 0 || exit 0; /usr/bin/systemd-run --quiet --no-block /usr/lib/udev/kdump-udev-throttler'" - -LABEL="kdump_reload_end" diff --git a/COPYING b/COPYING deleted file mode 100644 index d159169..0000000 --- a/COPYING +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/Makefile b/Makefile deleted file mode 100644 index e1a511c..0000000 --- a/Makefile +++ /dev/null @@ -1,83 +0,0 @@ -prefix ?= /usr -libdir ?= ${prefix}/lib -datadir ?= ${prefix}/share -pkglibdir ?= ${libdir}/kdump -sysconfdir ?= /etc -bindir ?= ${prefix}/bin -sbindir ?= ${prefix}/sbin -mandir ?= ${prefix}/share/man -localstatedir ?= /var -sharedstatedir ?= /var/lib -udevrulesdir ?= ${libdir}/udev/rules.d -systemdsystemunitdir ?= ${libdir}/systemd/system/ -ARCH ?= $(shell uname -m) -dracutmoddir = $(DESTDIR)${libdir}/dracut/modules.d -kdumpbasemoddir = $(dracutmoddir)/99kdumpbase - -dracut-modules: - mkdir -p $(dracutmoddir) - mkdir -p -m755 $(kdumpbasemoddir) - - install -m 755 dracut-kdump.sh $(kdumpbasemoddir)/kdump.sh - install -m 755 dracut-module-setup.sh $(kdumpbasemoddir)/module-setup.sh - install -m 755 dracut-monitor_dd_progress.sh $(kdumpbasemoddir)/monitor_dd_progress.sh - install -m 644 dracut-kdump-emergency.service $(kdumpbasemoddir)/kdump-emergency.service - install -m 644 dracut-kdump-capture.service $(kdumpbasemoddir)/kdump-capture.service - install -m 644 dracut-kdump-emergency.target $(kdumpbasemoddir)/kdump-emergency.target - - mkdir -p -m755 $(dracutmoddir)/99earlykdump - install -m 755 dracut-early-kdump.sh $(dracutmoddir)/99earlykdump/kdump.sh - install -m 755 dracut-early-kdump-module-setup.sh $(dracutmoddir)/99earlykdump/kdump-module-setup.sh - -ifeq ($(ARCH), $(filter ppc64le ppc64,$(ARCH))) - mkdir -p -m755 $(dracutmoddir)/99zz-fadumpinit - install -m 755 dracut-fadump-init-fadump.sh $(dracutmoddir)/99zz-fadumpinit/init-fadump.sh - install -m 755 dracut-fadump-module-setup.sh $(dracutmoddir)/99zz-fadumpinit/module-setup.sh -endif - -kdump-conf: gen-kdump-conf.sh - ./gen-kdump-conf.sh $(ARCH) > kdump.conf - -kdump-sysconfig: gen-kdump-sysconfig.sh - ./gen-kdump-sysconfig.sh $(ARCH) > kdump.sysconfig - -manpages: - install -D -m 644 mkdumprd.8 kdumpctl.8 -t $(DESTDIR)$(mandir)/man8 - install -D -m 644 kdump.conf.5 $(DESTDIR)$(mandir)/man5/kdump.conf.5 - -install: dracut-modules kdump-conf kdump-sysconfig manpages - mkdir -p $(DESTDIR)$(pkglibdir) - mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/pre.d - mkdir -p -m755 $(DESTDIR)$(sysconfdir)/kdump/post.d - mkdir -p -m755 $(DESTDIR)$(localstatedir)/crash - mkdir -p -m755 $(DESTDIR)$(udevrulesdir) - mkdir -p -m755 $(DESTDIR)$(sharedstatedir)/kdump - mkdir -p -m755 $(DESTDIR)$(libdir)/kernel/install.d/ - - install -D -m 755 kdumpctl $(DESTDIR)$(bindir)/kdumpctl - install -D -m 755 mkdumprd $(DESTDIR)$(sbindir)/mkdumprd - install -D -m 644 kdump.conf $(DESTDIR)$(sysconfdir) - install -D -m 644 kdump.sysconfig $(DESTDIR)$(sysconfdir)/sysconfig/kdump - install -D -m 755 kdump-lib.sh kdump-lib-initramfs.sh kdump-logger.sh -t $(DESTDIR)$(pkglibdir) - -ifeq ($(ARCH), $(filter ppc64le ppc64,$(ARCH))) - install -m 755 mkfadumprd $(DESTDIR)$(sbindir) - install -m 755 kdump-migrate-action.sh kdump-restart.sh -t $(DESTDIR)$(pkglibdir) - install -m 755 60-fadump.install $(DESTDIR)$(libdir)/kernel/install.d/ -endif - -ifneq ($(ARCH),s390x) - install -m 755 kdump-udev-throttler $(DESTDIR)$(udevrulesdir)/../kdump-udev-throttler - # For s390x the ELF header is created in the kdump kernel and therefore kexec - # udev rules are not required -ifeq ($(ARCH), $(filter ppc64le ppc64,$(ARCH))) - install -m 644 98-kexec.rules.ppc64 $(DESTDIR)$(udevrulesdir)/98-kexec.rules -else - install -m 644 98-kexec.rules $(DESTDIR)$(udevrulesdir)/98-kexec.rules -endif -endif - - install -D -m 644 kdump.service $(DESTDIR)$(systemdsystemunitdir)/kdump.service - install -m 755 -D kdump-dep-generator.sh $(DESTDIR)$(libdir)/systemd/system-generators/kdump-dep-generator.sh - install -m 755 60-kdump.install $(DESTDIR)$(libdir)/kernel/install.d/ - install -m 755 92-crashkernel.install $(DESTDIR)$(libdir)/kernel/install.d/ diff --git a/crashkernel-howto.txt b/crashkernel-howto.txt deleted file mode 100644 index 54e1141..0000000 --- a/crashkernel-howto.txt +++ /dev/null @@ -1,120 +0,0 @@ -Introduction -============ - -This document describes features the kexec-tools package provides for setting -and estimating the crashkernel value. - -Kdump lives in a pre-reserved chunk of memory, and the size of the reserved -memory is specified by the `crashkernel=` kernel parameter. It's hard to -estimate an accurate `crashkernel=` value, so it's always recommended to test -kdump after you updated the `crashkernel=` value or changed the dump target. - - -Default crashkernel value -========================= - -Latest kexec-tools provides "kdumpctl get-default-crashkernel" to retrieve -the default crashkernel value, - - $ echo $(kdumpctl get-default-crashkernel) - 1G-4G:192M,4G-64G:256M,64G-:512M - -It will be taken as the default value of 'crashkernel=', you can use -this value as a reference for setting crashkernel value manually. - - -New installed system -==================== - -Anaconda is the OS installer which sets all the kernel boot cmdline on a newly -installed system. If kdump is enabled during Anaconda installation, Anaconda -will use the default crashkernel value as the default `crashkernel=` value on -the newly installed system. - -Users can override the value during Anaconda installation manually. - - -Auto update of crashkernel boot parameter -========================================= - -A new release of kexec-tools could update the default crashkernel value. By -default, kexec-tools would reset crashkernel to the new default value if it -detects the old default crashkernel value is used by installed kernels. If you -don't want kexec-tools to update the old default crashkernel to the new default -crashkernel, you can change auto_reset_crashkernel to no in kdump.conf. - -Supported Bootloaders ---------------------- - -This auto update only works with GRUB2 and ZIPL, as kexec-tools heavily depends -on `grubby`. If other boot loaders are used, the user will have to update the -`crashkernel=` value manually. - - -Reset crashkernel to default value -================================== - -kexec-tools only perform the auto update of crashkernel value when it can -confirm the boot kernel's crashkernel value is using its corresponding default -value and auto_reset_crashkernel=yes in kdump.conf. In other cases, the user -can reset the crashkernel value by themselves. - -Reset using kdumpctl --------------------- - -To make it easier to reset the `crashkernel=` kernel cmdline to this default -value properly, `kdumpctl` also provides a sub-command: - - `kdumpctl reset-crashkernel [--kernel=path_to_kernel] [--reboot]` - -This command will reset the bootloader's kernel cmdline to the default value. -It will also update bootloader config if the bootloader has a standalone config -file. User will have to reboot the machine after this command to make it take -effect if --reboot is not specified. For more details, please refer to the -reset-crashkernel command in `man kdumpctl`. - -Reset manually --------------- - -To reset the crashkernel value manually, it's recommended to use utils like -`grubby`. A one liner script for resetting `crashkernel=` value of all installed -kernels to the default value is: - - grubby --update-kernel ALL --args "crashkernel=$(kdumpctl get-default-crashkernel)" - -NOTE: On s390x you also need to run zipl for the change to take effect. - -Estimate crashkernel -==================== - -The best way to estimate a usable crashkernel value is by testing kdump -manually. And you can set crashkernel to a large value, then adjust the -crashkernel value to an acceptable value gradually. - -`kdumpctl` also provides a sub-command for doing rough estimating without -triggering kdump: - - `kdumpctl estimate` - -The output will be like this: - -``` - Encrypted kdump target requires extra memory, assuming using the keyslot with minimum memory requirement - - Reserved crashkernel: 256M - Recommended crashkernel: 655M - - Kernel image size: 47M - Kernel modules size: 12M - Initramfs size: 19M - Runtime reservation: 64M - LUKS required size: 512M - Large modules: - xfs: 1892352 - nouveau: 2318336 - WARNING: Current crashkernel size is lower than recommended size 655M. -``` - -It will generate a summary report about the estimated memory consumption -of each component of kdump. The value may not be accurate enough, but -would be a good start for finding a suitable crashkernel value. diff --git a/dracut-early-kdump-module-setup.sh b/dracut-early-kdump-module-setup.sh deleted file mode 100755 index 0451118..0000000 --- a/dracut-early-kdump-module-setup.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -. /etc/sysconfig/kdump - -KDUMP_KERNEL="" -KDUMP_INITRD="" - -check() { - if [[ ! -f /etc/sysconfig/kdump ]] || [[ ! -f /lib/kdump/kdump-lib.sh ]] \ - || [[ -n ${IN_KDUMP} ]]; then - return 1 - fi - return 255 -} - -depends() { - echo "base shutdown" - return 0 -} - -prepare_kernel_initrd() { - . /lib/kdump/kdump-lib.sh - - prepare_kdump_bootinfo - - # $kernel is a variable from dracut - if [[ $KDUMP_KERNELVER != "$kernel" ]]; then - dwarn "Using kernel version '$KDUMP_KERNELVER' for early kdump," \ - "but the initramfs is generated for kernel version '$kernel'" - fi -} - -install() { - prepare_kernel_initrd - if [[ ! -f $KDUMP_KERNEL ]]; then - derror "Could not find required kernel for earlykdump," \ - "earlykdump will not work!" - return 1 - fi - if [[ ! -f $KDUMP_INITRD ]]; then - derror "Could not find required kdump initramfs for earlykdump," \ - "please ensure kdump initramfs is generated first," \ - "earlykdump will not work!" - return 1 - fi - - inst_multiple tail find cut dirname hexdump - inst_simple "/etc/sysconfig/kdump" - inst_binary "/usr/sbin/kexec" - inst_binary "/usr/bin/gawk" "/usr/bin/awk" - inst_binary "/usr/bin/logger" "/usr/bin/logger" - inst_binary "/usr/bin/printf" "/usr/bin/printf" - inst_binary "/usr/bin/xargs" "/usr/bin/xargs" - inst_script "/lib/kdump/kdump-lib.sh" "/lib/kdump-lib.sh" - inst_script "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump/kdump-lib-initramfs.sh" - inst_script "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh" - inst_hook cmdline 00 "$moddir/early-kdump.sh" - inst_binary "$KDUMP_KERNEL" - inst_binary "$KDUMP_INITRD" - - ln_r "$KDUMP_KERNEL" "/boot/kernel-earlykdump" - ln_r "$KDUMP_INITRD" "/boot/initramfs-earlykdump" - - chmod -x "${initdir}/$KDUMP_KERNEL" -} diff --git a/dracut-early-kdump.sh b/dracut-early-kdump.sh deleted file mode 100755 index 4fd8e90..0000000 --- a/dracut-early-kdump.sh +++ /dev/null @@ -1,79 +0,0 @@ -#! /bin/bash - -KEXEC=/sbin/kexec -standard_kexec_args="-p" - -EARLY_KDUMP_INITRD="" -EARLY_KDUMP_KERNEL="" -EARLY_KDUMP_CMDLINE="" -EARLY_KEXEC_ARGS="" - -. /etc/sysconfig/kdump -. /lib/dracut-lib.sh -. /lib/kdump-lib.sh -. /lib/kdump-logger.sh - -# initiate the kdump logger -if ! dlog_init; then - echo "failed to initiate the kdump logger." - exit 1 -fi - -prepare_parameters() -{ - EARLY_KDUMP_CMDLINE=$(prepare_cmdline "${KDUMP_COMMANDLINE}" "${KDUMP_COMMANDLINE_REMOVE}" "${KDUMP_COMMANDLINE_APPEND}") - EARLY_KDUMP_KERNEL="/boot/kernel-earlykdump" - EARLY_KDUMP_INITRD="/boot/initramfs-earlykdump" -} - -early_kdump_load() -{ - if ! check_kdump_feasibility; then - return 1 - fi - - if is_fadump_capable; then - dwarn "WARNING: early kdump doesn't support fadump." - return 1 - fi - - if is_kernel_loaded "kdump"; then - return 1 - fi - - prepare_parameters - - EARLY_KEXEC_ARGS=$(prepare_kexec_args "${KEXEC_ARGS}") - - # 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" - - # shellcheck disable=SC2086 - if $KEXEC $EARLY_KEXEC_ARGS $standard_kexec_args \ - --command-line="$EARLY_KDUMP_CMDLINE" \ - --initrd=$EARLY_KDUMP_INITRD $EARLY_KDUMP_KERNEL; then - dinfo "kexec: loaded early-kdump kernel" - return 0 - else - derror "kexec: failed to load early-kdump kernel" - return 1 - fi -} - -set_early_kdump() -{ - if getargbool 0 rd.earlykdump; then - dinfo "early-kdump is enabled." - early_kdump_load - else - dinfo "early-kdump is disabled." - fi - - return 0 -} - -set_early_kdump diff --git a/dracut-fadump-init-fadump.sh b/dracut-fadump-init-fadump.sh deleted file mode 100755 index 94a3751..0000000 --- a/dracut-fadump-init-fadump.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -export PATH=/usr/bin:/usr/sbin -export SYSTEMD_IN_INITRD=lenient - -[ -e /proc/mounts ] || - (mkdir -p /proc && mount -t proc -o nosuid,noexec,nodev proc /proc) - -grep -q '^sysfs /sys sysfs' /proc/mounts || - (mkdir -p /sys && mount -t sysfs -o nosuid,noexec,nodev sysfs /sys) - -grep -q '^none / ' /proc/mounts || grep -q '^rootfs / ' /proc/mounts && ROOTFS_IS_RAMFS=1 - -if [ -f /proc/device-tree/rtas/ibm,kernel-dump ] || [ -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then - mkdir /newroot - mount -t ramfs ramfs /newroot - - if [ $ROOTFS_IS_RAMFS ]; then - for FILE in $(ls -A /fadumproot/); do - mv /fadumproot/$FILE /newroot/ - done - exec switch_root /newroot /init - else - mkdir /newroot/sys /newroot/proc /newroot/dev /newroot/run /newroot/oldroot - - grep -q '^devtmpfs /dev devtmpfs' /proc/mounts && mount --move /dev /newroot/dev - grep -q '^tmpfs /run tmpfs' /proc/mounts && mount --move /run /newroot/run - mount --move /sys /newroot/sys - mount --move /proc /newroot/proc - - cp --reflink=auto --sparse=auto --preserve=mode,timestamps,links -dfr /fadumproot/. /newroot/ - cd /newroot && pivot_root . oldroot - - loop=1 - while [ $loop ]; do - unset loop - while read -r _ mp _; do - case $mp in - /oldroot/*) umount -d "$mp" && loop=1 ;; - esac - done $KDUMP_CONF_PARSED - -get_kdump_confs() -{ - while read -r config_opt config_val; do - # remove inline comments after the end of a directive. - case "$config_opt" in - path) - KDUMP_PATH="$config_val" - ;; - core_collector) - [ -n "$config_val" ] && CORE_COLLECTOR="$config_val" - ;; - sshkey) - if [ -f "$config_val" ]; then - SSH_KEY_LOCATION=$config_val - fi - ;; - kdump_pre) - KDUMP_PRE="$config_val" - ;; - kdump_post) - KDUMP_POST="$config_val" - ;; - fence_kdump_args) - FENCE_KDUMP_ARGS="$config_val" - ;; - fence_kdump_nodes) - FENCE_KDUMP_NODES="$config_val" - ;; - failure_action | default) - case $config_val in - shell) - FAILURE_ACTION="kdump_emergency_shell" - ;; - reboot) - FAILURE_ACTION="systemctl reboot -f && exit" - ;; - halt) - FAILURE_ACTION="halt && exit" - ;; - poweroff) - FAILURE_ACTION="systemctl poweroff -f && exit" - ;; - dump_to_rootfs) - FAILURE_ACTION="dump_to_rootfs" - ;; - esac - ;; - final_action) - case $config_val in - reboot) - FINAL_ACTION="systemctl reboot -f" - ;; - halt) - FINAL_ACTION="halt" - ;; - poweroff) - FINAL_ACTION="systemctl poweroff -f" - ;; - esac - ;; - esac - done < "$KDUMP_CONF_PARSED" - - if [ -z "$CORE_COLLECTOR" ]; then - CORE_COLLECTOR="$DEFAULT_CORE_COLLECTOR" - if is_ssh_dump_target || is_raw_dump_target; then - CORE_COLLECTOR="$CORE_COLLECTOR -F" - fi - fi -} - -# store the kexec kernel log to a file. -save_log() -{ - # LOG_OP is empty when log can't be saved, eg. raw target - [ -n "$KDUMP_LOG_OP" ] || return - - dmesg -T > $KDUMP_LOG_FILE - - if command -v journalctl > /dev/null; then - journalctl -ab >> $KDUMP_LOG_FILE - fi - chmod 600 $KDUMP_LOG_FILE - - dinfo "saving the $KDUMP_LOG_FILE to $KDUMP_LOG_DEST/" - - eval "$KDUMP_LOG_OP" -} - -# $1: dump path, must be a mount point -dump_fs() -{ - ddebug "dump_fs _mp=$1" - - if ! is_mounted "$1"; then - dinfo "dump path '$1' is not mounted, trying to mount..." - if ! mount --target "$1"; then - derror "failed to dump to '$1', it's not a mount point!" - return 1 - fi - fi - - # Remove -F in makedumpfile case. We don't want a flat format dump here. - case $CORE_COLLECTOR in - *makedumpfile*) - CORE_COLLECTOR=$(echo "$CORE_COLLECTOR" | sed -e "s/-F//g") - ;; - esac - - _dump_fs_path=$(echo "$1/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) - dinfo "saving to $_dump_fs_path" - - # Only remount to read-write mode if the dump target is mounted read-only. - _dump_mnt_op=$(get_mount_info OPTIONS target "$1" -f) - case $_dump_mnt_op in - ro*) - dinfo "Remounting the dump target in rw mode." - mount -o remount,rw "$1" || return 1 - ;; - esac - - mkdir -p "$_dump_fs_path" || return 1 - - save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_fs_path" - save_opalcore_fs "$_dump_fs_path" - - dinfo "saving vmcore" - KDUMP_LOG_DEST=$_dump_fs_path/ - KDUMP_LOG_OP="mv '$KDUMP_LOG_FILE' '$KDUMP_LOG_DEST/'" - - $CORE_COLLECTOR /proc/vmcore "$_dump_fs_path/vmcore-incomplete" - _dump_exitcode=$? - if [ $_dump_exitcode -eq 0 ]; then - sync -f "$_dump_fs_path/vmcore-incomplete" - _sync_exitcode=$? - if [ $_sync_exitcode -eq 0 ]; then - mv "$_dump_fs_path/vmcore-incomplete" "$_dump_fs_path/vmcore" - dinfo "saving vmcore complete" - else - derror "sync vmcore failed, exitcode:$_sync_exitcode" - return 1 - fi - else - derror "saving vmcore failed, exitcode:$_dump_exitcode" - return 1 - fi - - # improper kernel cmdline can cause the failure of echo, we can ignore this kind of failure - return 0 -} - -# $1: dmesg collector -# $2: dump path -save_vmcore_dmesg_fs() -{ - dinfo "saving vmcore-dmesg.txt to $2" - if $1 /proc/vmcore > "$2/vmcore-dmesg-incomplete.txt"; then - mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" - chmod 600 "$2/vmcore-dmesg.txt" - - # Make sure file is on disk. There have been instances where later - # saving vmcore failed and system rebooted without sync and there - # was no vmcore-dmesg.txt available. - sync - dinfo "saving vmcore-dmesg.txt complete" - else - if [ -f "$2/vmcore-dmesg-incomplete.txt" ]; then - chmod 600 "$2/vmcore-dmesg-incomplete.txt" - fi - derror "saving vmcore-dmesg.txt failed" - fi -} - -# $1: dump path -save_opalcore_fs() -{ - if [ ! -f $OPALCORE ]; then - # Check if we are on an old kernel that uses a different path - if [ -f /sys/firmware/opal/core ]; then - OPALCORE="/sys/firmware/opal/core" - else - return 0 - fi - fi - - dinfo "saving opalcore:$OPALCORE to $1/opalcore" - if ! cp $OPALCORE "$1/opalcore"; then - derror "saving opalcore failed" - return 1 - fi - - sync - dinfo "saving opalcore complete" - return 0 -} - -dump_to_rootfs() -{ - - if [ "$(systemctl status dracut-initqueue | sed -n "s/^\s*Active: \(\S*\)\s.*$/\1/p")" = "inactive" ]; then - dinfo "Trying to bring up initqueue for rootfs mount" - systemctl start dracut-initqueue - fi - - dinfo "Clean up dead systemd services" - systemctl cancel - dinfo "Waiting for rootfs mount, will timeout after 90 seconds" - systemctl start --no-block sysroot.mount - - _loop=0 - while [ $_loop -lt 90 ] && ! is_mounted /sysroot; do - sleep 1 - _loop=$((_loop + 1)) - done - - if ! is_mounted /sysroot; then - derror "Failed to mount rootfs" - return - fi - - ddebug "NEWROOT=$NEWROOT" - dump_fs $NEWROOT -} - -kdump_emergency_shell() -{ - ddebug "Switching to kdump emergency shell..." - - [ -f /etc/profile ] && . /etc/profile - export PS1='kdump:${PWD}# ' - - . /lib/dracut-lib.sh - if [ -f /dracut-state.sh ]; then - . /dracut-state.sh 2> /dev/null - fi - - source_conf /etc/conf.d - - type plymouth > /dev/null 2>&1 && plymouth quit - - source_hook "emergency" - while read -r _tty rest; do - ( - echo - echo - echo 'Entering kdump emergency mode.' - echo 'Type "journalctl" to view system logs.' - echo 'Type "rdsosreport" to generate a sosreport, you can then' - echo 'save it elsewhere and attach it to a bug report.' - echo - echo - ) > "/dev/$_tty" - done < /proc/consoles - sh -i -l - /bin/rm -f -- /.console_lock -} - -do_failure_action() -{ - dinfo "Executing failure action $FAILURE_ACTION" - eval $FAILURE_ACTION -} - -do_final_action() -{ - dinfo "Executing final action $FINAL_ACTION" - eval $FINAL_ACTION -} - -do_dump() -{ - eval $DUMP_INSTRUCTION - _ret=$? - - if [ $_ret -ne 0 ]; then - derror "saving vmcore failed" - fi - - return $_ret -} - -do_kdump_pre() -{ - if [ -n "$KDUMP_PRE" ]; then - "$KDUMP_PRE" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$KDUMP_PRE exited with $_ret status" - return $_ret - fi - fi - - # if any script fails, it just raises warning and continues - if [ -d /etc/kdump/pre.d ]; then - for file in /etc/kdump/pre.d/*; do - "$file" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$file exited with $_ret status" - fi - done - fi - return 0 -} - -do_kdump_post() -{ - if [ -d /etc/kdump/post.d ]; then - for file in /etc/kdump/post.d/*; do - "$file" "$1" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$file exited with $_ret status" - fi - done - fi - - if [ -n "$KDUMP_POST" ]; then - "$KDUMP_POST" "$1" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "$KDUMP_POST exited with $_ret status" - fi - fi -} - -# $1: block target, eg. /dev/sda -dump_raw() -{ - [ -b "$1" ] || return 1 - - dinfo "saving to raw disk $1" - - if ! echo "$CORE_COLLECTOR" | grep -q makedumpfile; then - _src_size=$(stat --format %s /proc/vmcore) - _src_size_mb=$((_src_size / 1048576)) - /kdumpscripts/monitor_dd_progress.sh $_src_size_mb & - fi - - dinfo "saving vmcore" - $CORE_COLLECTOR /proc/vmcore | dd of="$1" bs=$DD_BLKSIZE >> /tmp/dd_progress_file 2>&1 || return 1 - sync - - dinfo "saving vmcore complete" - return 0 -} - -# $1: ssh key file -# $2: ssh address in @ format -dump_ssh() -{ - _ret=0 - _ssh_opt="-i $1 -o BatchMode=yes -o StrictHostKeyChecking=yes" - _ssh_dir="$KDUMP_PATH/$HOST_IP-$DATEDIR" - if is_ipv6_address "$2"; then - _scp_address=${2%@*}@"[${2#*@}]" - else - _scp_address=$2 - fi - - dinfo "saving to $2:$_ssh_dir" - - cat /var/lib/random-seed > /dev/urandom - ssh -q $_ssh_opt "$2" mkdir -p "$_ssh_dir" || return 1 - - save_vmcore_dmesg_ssh "$DMESG_COLLECTOR" "$_ssh_dir" "$_ssh_opt" "$2" - - dinfo "saving vmcore" - - KDUMP_LOG_DEST=$2:$_ssh_dir/ - KDUMP_LOG_OP="scp -q $_ssh_opt '$KDUMP_LOG_FILE' '$_scp_address:$_ssh_dir/'" - - save_opalcore_ssh "$_ssh_dir" "$_ssh_opt" "$2" "$_scp_address" - - if [ "${CORE_COLLECTOR%%[[:blank:]]*}" = "scp" ]; then - scp -q $_ssh_opt /proc/vmcore "$_scp_address:$_ssh_dir/vmcore-incomplete" - _ret=$? - _vmcore="vmcore" - else - $CORE_COLLECTOR /proc/vmcore | ssh $_ssh_opt "$2" "umask 0077 && dd bs=512 of='$_ssh_dir/vmcore-incomplete'" - _ret=$? - _vmcore="vmcore.flat" - fi - - if [ $_ret -eq 0 ]; then - ssh $_ssh_opt "$2" "mv '$_ssh_dir/vmcore-incomplete' '$_ssh_dir/$_vmcore'" - _ret=$? - if [ $_ret -ne 0 ]; then - derror "moving vmcore failed, exitcode:$_ret" - else - dinfo "saving vmcore complete" - fi - else - derror "saving vmcore failed, exitcode:$_ret" - fi - - return $_ret -} - -# $1: dump path -# $2: ssh opts -# $3: ssh address in @ format -# $4: scp address, similar with ssh address but IPv6 addresses are quoted -save_opalcore_ssh() -{ - if [ ! -f $OPALCORE ]; then - # Check if we are on an old kernel that uses a different path - if [ -f /sys/firmware/opal/core ]; then - OPALCORE="/sys/firmware/opal/core" - else - return 0 - fi - fi - - dinfo "saving opalcore:$OPALCORE to $3:$1" - - if ! scp $2 $OPALCORE "$4:$1/opalcore-incomplete"; then - derror "saving opalcore failed" - return 1 - fi - - ssh $2 "$3" mv "$1/opalcore-incomplete" "$1/opalcore" - dinfo "saving opalcore complete" - return 0 -} - -# $1: dmesg collector -# $2: dump path -# $3: ssh opts -# $4: ssh address in @ format -save_vmcore_dmesg_ssh() -{ - dinfo "saving vmcore-dmesg.txt to $4:$2" - if $1 /proc/vmcore | ssh $3 "$4" "umask 0077 && dd of='$2/vmcore-dmesg-incomplete.txt'"; then - ssh -q $3 "$4" mv "$2/vmcore-dmesg-incomplete.txt" "$2/vmcore-dmesg.txt" - dinfo "saving vmcore-dmesg.txt complete" - else - derror "saving vmcore-dmesg.txt failed" - fi -} - -wait_online_network() -{ - # In some cases, network may still not be ready because nm-online is called - # with "-s" which means to wait for NetworkManager startup to complete, rather - # than waiting for network connectivity specifically. Wait 10mins more for the - # network to be truely ready in these cases. - _loop=0 - while [ $_loop -lt 600 ]; do - sleep 1 - _loop=$((_loop + 1)) - if _route=$(kdump_get_ip_route "$1" 2> /dev/null); then - printf "%s" "$_route" - return - else - dwarn "Waiting for network to be ready (${_loop}s / 10min)" - fi - done - - derror "Oops. The network still isn't ready after waiting 10mins." - exit 1 -} - -get_host_ip() -{ - - if ! is_nfs_dump_target && ! is_ssh_dump_target; then - return 0 - fi - - _kdump_remote_ip=$(getarg kdump_remote_ip=) - - if [ -z "$_kdump_remote_ip" ]; then - derror "failed to get remote IP address!" - return 1 - fi - - if ! _route=$(wait_online_network "$_kdump_remote_ip"); then - return 1 - fi - - _netdev=$(kdump_get_ip_route_field "$_route" "dev") - - if ! _kdumpip=$(ip addr show dev "$_netdev" | grep '[ ]*inet'); then - derror "Failed to get IP of $_netdev" - return 1 - fi - - _kdumpip=$(echo "$_kdumpip" | head -n 1 | awk '{print $2}') - _kdumpip="${_kdumpip%%/*}" - HOST_IP=$_kdumpip -} - -read_kdump_confs() -{ - if [ ! -f "$KDUMP_CONFIG_FILE" ]; then - derror "$KDUMP_CONFIG_FILE not found" - return - fi - - get_kdump_confs - - # rescan for add code for dump target - while read -r config_opt config_val; do - # remove inline comments after the end of a directive. - case "$config_opt" in - dracut_args) - config_val=$(get_dracut_args_target "$config_val") - if [ -n "$config_val" ]; then - config_val=$(get_mntpoint_from_target "$config_val") - DUMP_INSTRUCTION="dump_fs $config_val" - fi - ;; - ext[234] | xfs | btrfs | minix | nfs | virtiofs) - config_val=$(get_mntpoint_from_target "$config_val") - DUMP_INSTRUCTION="dump_fs $config_val" - ;; - raw) - DUMP_INSTRUCTION="dump_raw $config_val" - ;; - ssh) - DUMP_INSTRUCTION="dump_ssh $SSH_KEY_LOCATION $config_val" - ;; - esac - done < "$KDUMP_CONF_PARSED" -} - -fence_kdump_notify() -{ - if [ -n "$FENCE_KDUMP_NODES" ]; then - # shellcheck disable=SC2086 - $FENCE_KDUMP_SEND $FENCE_KDUMP_ARGS $FENCE_KDUMP_NODES & - fi -} - -if [ "$1" = "--error-handler" ]; then - get_kdump_confs - do_failure_action - do_final_action - - exit $? -fi - -# continue here only if we have to save dump. -if [ -f /etc/fadump.initramfs ] && [ ! -f /proc/device-tree/rtas/ibm,kernel-dump ] && [ ! -f /proc/device-tree/ibm,opal/dump/mpipl-boot ]; then - exit 0 -fi - -read_kdump_confs -fence_kdump_notify - -if ! get_host_ip; then - derror "get_host_ip exited with non-zero status!" - exit 1 -fi - -if [ -z "$DUMP_INSTRUCTION" ]; then - DUMP_INSTRUCTION="dump_fs $NEWROOT" -fi - -if ! do_kdump_pre; then - derror "kdump_pre script exited with non-zero status!" - do_final_action - # During systemd service to reboot the machine, stop this shell script running - exit 1 -fi -make_trace_mem "kdump saving vmcore" '1:shortmem' '2+:mem' '3+:slab' -do_dump -DUMP_RETVAL=$? - -if ! do_kdump_post $DUMP_RETVAL; then - derror "kdump_post script exited with non-zero status!" -fi - -save_log - -if [ $DUMP_RETVAL -ne 0 ]; then - exit 1 -fi - -do_final_action diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh deleted file mode 100755 index 7e1cb9f..0000000 --- a/dracut-module-setup.sh +++ /dev/null @@ -1,1083 +0,0 @@ -#!/bin/bash - -_DRACUT_KDUMP_NM_TMP_DIR="$DRACUT_TMPDIR/$$-DRACUT_KDUMP_NM" - -_save_kdump_netifs() { - unique_netifs[$1]=1 -} - -_get_kdump_netifs() { - echo -n "${!unique_netifs[@]}" -} - -kdump_module_init() { - if ! [[ -d "${initdir}/tmp" ]]; then - mkdir -p "${initdir}/tmp" - fi - - mkdir -p "$_DRACUT_KDUMP_NM_TMP_DIR" - - . /lib/kdump/kdump-lib.sh -} - -check() { - [[ $debug ]] && set -x - #kdumpctl sets this explicitly - if [[ -z $IN_KDUMP ]] || [[ ! -f /etc/kdump.conf ]]; then - return 1 - fi - if [[ "$(uname -m)" == "s390x" ]]; then - require_binaries chzdev || return 1 - fi - return 0 -} - -depends() { - local _dep="base shutdown" - - kdump_module_init - - add_opt_module() { - [[ " $omit_dracutmodules " != *\ $1\ * ]] && _dep="$_dep $1" - } - - if is_squash_available; then - 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 is_lvm2_thinp_dump_target; then - if dracut --list-modules | grep -q lvmthinpool-monitor; then - add_opt_module lvmthinpool-monitor - else - dwarning "Required lvmthinpool-monitor modules is missing! Please upgrade dracut >= 057." - fi - fi - - if [[ "$(uname -m)" == "s390x" ]]; then - _dep="$_dep znet" - fi - - if [[ -n "$(ls -A /sys/class/drm 2> /dev/null)" ]] || [[ -d /sys/module/hyperv_fb ]]; then - add_opt_module drm - fi - - if is_generic_fence_kdump || is_pcs_fence_kdump; then - _dep="$_dep network" - fi - - echo "$_dep" -} - -kdump_is_bridge() { - [[ -d /sys/class/net/"$1"/bridge ]] -} - -kdump_is_bond() { - [[ -d /sys/class/net/"$1"/bonding ]] -} - -kdump_is_team() { - [[ -f /usr/bin/teamnl ]] && teamnl "$1" ports &> /dev/null -} - -kdump_is_vlan() { - [[ -f /proc/net/vlan/"$1" ]] -} - -# $1: repeat times -# $2: string to be repeated -# $3: separator -repeatedly_join_str() { - local _count="$1" - local _str="$2" - local _separator="$3" - local i _res - - if [[ $_count -le 0 ]]; then - echo -n "" - return - fi - - i=0 - _res="$_str" - ((_count--)) - - while [[ $i -lt $_count ]]; do - ((i++)) - _res="${_res}${_separator}${_str}" - done - echo -n "$_res" -} - -# $1: prefix -# $2: ipv6_flag="-6" indicates it's IPv6 -# Given a prefix, calculate the netmask (equivalent of "ipcalc -m") -# by concatenating three parts, -# 1) the groups with all bits set 1 -# 2) a group with partial bits set to 0 -# 3) the groups with all bits set to 0 -cal_netmask_by_prefix() { - local _prefix="$1" - local _ipv6_flag="$2" _ipv6 - local _bits_per_octet=8 - local _count _res _octets_per_group _octets_total _seperator _total_groups - local _max_group_value _max_group_value_repr _bits_per_group _tmp _zero_bits - - if [[ $_ipv6_flag == "-6" ]]; then - _ipv6=1 - else - _ipv6=0 - fi - - if [[ $_prefix -lt 0 || $_prefix -gt 128 ]] \ - || ( ((!_ipv6)) && [[ $_prefix -gt 32 ]]); then - derror "Bad prefix:$_prefix for calculating netmask" - exit 1 - fi - - if ((_ipv6)); then - _octets_per_group=2 - _octets_total=16 - _seperator=":" - else - _octets_per_group=1 - _octets_total=4 - _seperator="." - fi - - _total_groups=$((_octets_total / _octets_per_group)) - _bits_per_group=$((_octets_per_group * _bits_per_octet)) - _max_group_value=$(((1 << _bits_per_group) - 1)) - - if ((_ipv6)); then - _max_group_value_repr=$(printf "%x" $_max_group_value) - else - _max_group_value_repr="$_max_group_value" - fi - - _count=$((_prefix / _octets_per_group / _bits_per_octet)) - _first_part=$(repeatedly_join_str "$_count" "$_max_group_value_repr" "$_seperator") - _res="$_first_part" - - _tmp=$((_octets_total * _bits_per_octet - _prefix)) - _zero_bits=$((_tmp % _bits_per_group)) - if [[ $_zero_bits -ne 0 ]]; then - _second_part=$((_max_group_value >> _zero_bits << _zero_bits)) - if ((_ipv6)); then - _second_part=$(printf "%x" $_second_part) - fi - ((_count++)) - if [[ -z $_first_part ]]; then - _res="$_second_part" - else - _res="${_first_part}${_seperator}${_second_part}" - fi - fi - - _count=$((_total_groups - _count)) - if [[ $_count -eq 0 ]]; then - echo -n "$_res" - return - fi - - if ((_ipv6)) && [[ $_count -gt 1 ]]; then - # use condensed notion for IPv6 - _third_part=":" - else - _third_part=$(repeatedly_join_str "$_count" "0" "$_seperator") - fi - - if [[ -z $_res ]] && ((!_ipv6)); then - echo -n "${_third_part}" - else - echo -n "${_res}${_seperator}${_third_part}" - fi -} - -kdump_get_mac_addr() { - cat "/sys/class/net/$1/address" -} - -#Bonding or team master modifies the mac address -#of its slaves, we should use perm address -kdump_get_perm_addr() { - local addr - addr=$(ethtool -P "$1" | sed -e 's/Permanent address: //') - if [[ -z $addr ]] || [[ $addr == "00:00:00:00:00:00" ]]; then - derror "Can't get the permanent address of $1" - else - echo "$addr" - fi -} - -apply_nm_initrd_generator_timeouts() { - local _timeout_conf - - _timeout_conf=$_DRACUT_KDUMP_NM_TMP_DIR/timeout_conf - cat << EOF > "$_timeout_conf" -[device-95-kdump] -carrier-wait-timeout=30000 - -[connection-95-kdump] -ipv4.dhcp-timeout=90 -ipv6.dhcp-timeout=90 -EOF - - inst "$_timeout_conf" "/etc/NetworkManager/conf.d/95-kdump-timeouts.conf" -} - -use_ipv4_or_ipv6() { - local _netif=$1 _uuid=$2 - - if [[ -v "ipv4_usage[$_netif]" ]]; then - nmcli connection modify --temporary "$_uuid" ipv4.may-fail no &> >(ddebug) - fi - - if [[ -v "ipv6_usage[$_netif]" ]]; then - nmcli connection modify --temporary "$_uuid" ipv6.may-fail no &> >(ddebug) - fi - - if [[ -v "ipv4_usage[$_netif]" ]] && [[ ! -v "ipv6_usage[$_netif]" ]]; then - nmcli connection modify --temporary "$_uuid" ipv6.method disabled &> >(ddebug) - elif [[ ! -v "ipv4_usage[$_netif]" ]] && [[ -v "ipv6_usage[$_netif]" ]]; then - nmcli connection modify --temporary "$_uuid" ipv4.method disabled &> >(ddebug) - fi -} - -_clone_nmconnection() { - local _clone_output _name _unique_id - - _unique_id=$1 - _name=$(nmcli --get-values connection.id connection show "$_unique_id") - if _clone_output=$(nmcli connection clone --temporary uuid "$_unique_id" "$_name"); then - sed -E -n "s/.* \(.*\) cloned as.*\((.*)\)\.$/\1/p" <<< "$_clone_output" - return 0 - fi - - return 1 -} - -_match_nmconnection_by_mac() { - local _unique_id _dev _mac _mac_field - - _unique_id=$1 - _dev=$2 - - _mac=$(kdump_get_perm_addr "$_dev") - [[ $_mac != 'not set' ]] || return - _mac_field=$(nmcli --get-values connection.type connection show "$_unique_id").mac-address - nmcli connection modify --temporary "$_unique_id" "$_mac_field" "$_mac" &> >(ddebug) - nmcli connection modify --temporary "$_unique_id" "connection.interface-name" "" &> >(ddebug) -} - -# Clone and modify NM connection profiles -# -# This function makes use of "nmcli clone" to automatically convert ifcfg-* -# files to Networkmanager .nmconnection connection profiles and also modify the -# properties of .nmconnection if necessary. -clone_and_modify_nmconnection() { - local _dev _cloned_nmconnection_file_path _tmp_nmconnection_file_path _old_uuid _uuid - - _dev=$1 - _nmconnection_file_path=$2 - - _old_uuid=$(nmcli --get-values connection.uuid connection show filename "$_nmconnection_file_path") - - if ! _uuid=$(_clone_nmconnection "$_old_uuid"); then - derror "Failed to clone $_old_uuid" - exit 1 - fi - - use_ipv4_or_ipv6 "$_dev" "$_uuid" - - nmcli connection modify --temporary uuid "$_uuid" connection.wait-device-timeout 60000 &> >(ddebug) - # For physical NIC i.e. non-user created NIC, ask NM to match a - # connection profile based on MAC address - _match_nmconnection_by_mac "$_uuid" "$_dev" - - # If a value contain ":", nmcli by default escape it with "\:" because it - # also uses ":" as the delimiter to separate values. In our case, escaping is not needed. - _cloned_nmconnection_file_path=$(nmcli --escape no --get-values UUID,FILENAME connection show | sed -n "s/^${_uuid}://p") - _tmp_nmconnection_file_path=$_DRACUT_KDUMP_NM_TMP_DIR/$(basename "$_nmconnection_file_path") - cp "$_cloned_nmconnection_file_path" "$_tmp_nmconnection_file_path" - # change uuid back to old value in case it's refered by other connection - # profile e.g. connection.master could be interface name of the master - # device or UUID of the master connection. - sed -i -E "s/(^uuid=).*$/\1${_old_uuid}/g" "$_tmp_nmconnection_file_path" - nmcli connection del "$_uuid" &> >(ddebug) - echo -n "$_tmp_nmconnection_file_path" -} - -_install_nmconnection() { - local _src _nmconnection_name _dst - - _src=$1 - _nmconnection_name=$(basename "$_src") - _dst="/etc/NetworkManager/system-connections/$_nmconnection_name" - inst "$_src" "$_dst" -} - -kdump_install_nmconnections() { - local _netif _nm_conn_path _cloned_nm_path - - while IFS=: read -r _netif _nm_conn_path; do - [[ -v "unique_netifs[$_netif]" ]] || continue - if _cloned_nm_path=$(clone_and_modify_nmconnection "$_netif" "$_nm_conn_path"); then - _install_nmconnection "$_cloned_nm_path" - else - derror "Failed to install the .nmconnection for $_netif" - exit 1 - fi - done <<< "$(nmcli -t -f device,filename connection show --active)" - - # Stop dracut 35network-manger to calling nm-initrd-generator. - # Note this line of code can be removed after NetworkManager >= 1.35.2 - # gets released. - echo > "${initdir}/usr/libexec/nm-initrd-generator" -} - -kdump_install_nm_netif_allowlist() { - local _netif _except_netif _netif_allowlist _netif_allowlist_nm_conf - - for _netif in $1; do - _per_mac=$(kdump_get_perm_addr "$_netif") - if [[ "$_per_mac" != 'not set' ]]; then - _except_netif="mac:$_per_mac" - else - _except_netif="interface-name:$_netif" - fi - _netif_allowlist="${_netif_allowlist}except:${_except_netif};" - done - - _netif_allowlist_nm_conf=$_DRACUT_KDUMP_NM_TMP_DIR/netif_allowlist_nm_conf - cat << EOF > "$_netif_allowlist_nm_conf" -[device-others] -match-device=${_netif_allowlist} -managed=false -EOF - - inst "$_netif_allowlist_nm_conf" "/etc/NetworkManager/conf.d/10-kdump-netif_allowlist.conf" -} - -_get_nic_driver() { - ethtool -i "$1" | sed -n -E "s/driver: (.*)/\1/p" -} - -_get_hpyerv_physical_driver() { - local _physical_nic - - _physical_nic=$(find /sys/class/net/"$1"/ -name 'lower_*' | sed -En "s/\/.*lower_(.*)/\1/p") - [[ -n $_physical_nic ]] || return - _get_nic_driver "$_physical_nic" -} - -kdump_install_nic_driver() { - local _netif _driver _drivers - - _drivers=() - - for _netif in $1; do - [[ $_netif == lo ]] && continue - _driver=$(_get_nic_driver "$_netif") - if [[ -z $_driver ]]; then - derror "Failed to get the driver of $_netif" - exit 1 - fi - - if [[ $_driver == "802.1Q VLAN Support" ]]; then - # ethtool somehow doesn't return the driver name for a VLAN NIC - _driver=8021q - elif [[ $_driver == "team" ]]; then - # install the team mode drivers like team_mode_roundrobin.ko as well - _driver='=drivers/net/team' - elif [[ $_driver == "hv_netvsc" ]]; then - # A Hyper-V VM may have accelerated networking - # https://learn.microsoft.com/en-us/azure/virtual-network/accelerated-networking-overview - # Install the driver of physical NIC as well - _drivers+=("$(_get_hpyerv_physical_driver "$_netif")") - fi - - _drivers+=("$_driver") - done - - [[ -n ${_drivers[*]} ]] || return - instmods "${_drivers[@]}" -} - -kdump_setup_bridge() { - local _netdev=$1 - local _dev - for _dev in "/sys/class/net/$_netdev/brif/"*; do - [[ -e $_dev ]] || continue - _dev=${_dev##*/} - if kdump_is_bond "$_dev"; then - kdump_setup_bond "$_dev" || return 1 - elif kdump_is_team "$_dev"; then - kdump_setup_team "$_dev" - elif kdump_is_vlan "$_dev"; then - kdump_setup_vlan "$_dev" - fi - _save_kdump_netifs "$_dev" - done -} - -kdump_setup_bond() { - local _netdev="$1" - local _dev - - for _dev in $(< "/sys/class/net/$_netdev/bonding/slaves"); do - _save_kdump_netifs "$_dev" - done -} - -kdump_setup_team() { - local _netdev=$1 - local _dev - for _dev in $(teamnl "$_netdev" ports | awk -F':' '{print $2}'); do - _save_kdump_netifs "$_dev" - done -} - -kdump_setup_vlan() { - local _netdev=$1 - local _parent_netif - - _parent_netif="$(awk '/^Device:/{print $2}' /proc/net/vlan/"$_netdev")" - - #Just support vlan over bond and team - if kdump_is_bridge "$_parent_netif"; then - derror "Vlan over bridge is not supported!" - exit 1 - elif kdump_is_bond "$_parent_netif"; then - kdump_setup_bond "$_parent_netif" || return 1 - elif kdump_is_team "$_parent_netif"; then - kdump_setup_team "$_parent_netif" || return 1 - fi - - _save_kdump_netifs "$_parent_netif" -} - -# setup s390 znet -kdump_setup_znet() { - local _netif - local _tempfile=$(mktemp --tmpdir="$_DRACUT_KDUMP_NM_TMP_DIR" kdump-dracut-zdev.XXXXXX) - - if [[ "$(uname -m)" != "s390x" ]]; then - return - fi - - for _netif in $1; do - chzdev --export "$_tempfile" --active --by-interface "$_netif" \ - 2>&1 | ddebug - sed -i -e 's/^\[active /\[persistent /' "$_tempfile" - ddebug < "$_tempfile" - chzdev --import "$_tempfile" --persistent --base "/etc=$initdir/etc" \ - --yes --no-root-update --force 2>&1 | ddebug - lszdev --configured --persistent --info --by-interface "$_netif" \ - --base "/etc=$initdir/etc" 2>&1 | ddebug - done - rm -f "$_tempfile" -} - -kdump_get_remote_ip() { - local _remote _remote_temp - _remote=$(get_remote_host "$1") - if is_hostname "$_remote"; then - _remote_temp=$(getent ahosts "$_remote" | grep -v : | head -n 1) - if [[ -z $_remote_temp ]]; then - _remote_temp=$(getent ahosts "$_remote" | head -n 1) - fi - _remote=$(echo "$_remote_temp" | awk '{print $1}') - fi - echo "$_remote" -} - -# Collect netifs needed by kdump -# $1: destination host -kdump_collect_netif_usage() { - local _destaddr _srcaddr _route _netdev - - _destaddr=$(kdump_get_remote_ip "$1") - - if ! _route=$(kdump_get_ip_route "$_destaddr"); then - derror "Bad kdump network destination: $_destaddr" - exit 1 - fi - - _srcaddr=$(kdump_get_ip_route_field "$_route" "src") - _netdev=$(kdump_get_ip_route_field "$_route" "dev") - - if kdump_is_bridge "$_netdev"; then - kdump_setup_bridge "$_netdev" - elif kdump_is_bond "$_netdev"; then - kdump_setup_bond "$_netdev" || return 1 - elif kdump_is_team "$_netdev"; then - kdump_setup_team "$_netdev" - elif kdump_is_vlan "$_netdev"; then - kdump_setup_vlan "$_netdev" - fi - _save_kdump_netifs "$_netdev" - - if [[ ! -f ${initdir}/etc/cmdline.d/50neednet.conf ]]; then - # network-manager module needs this parameter - echo "rd.neednet" >> "${initdir}/etc/cmdline.d/50neednet.conf" - fi - - if [[ ! -f ${initdir}/etc/cmdline.d/60kdumpip.conf ]]; then - echo "kdump_remote_ip=$_destaddr" > "${initdir}/etc/cmdline.d/60kdumpip.conf" - fi - - if is_ipv6_address "$_srcaddr"; then - ipv6_usage[$_netdev]=1 - else - ipv4_usage[$_netdev]=1 - fi -} - -kdump_install_resolv_conf() { - local _resolv_conf=/etc/resolv.conf _nm_conf_dir=/etc/NetworkManager/conf.d - - # Some users may choose to manage /etc/resolve.conf manually [1] - # by setting dns=none or use a symbolic link resolve.conf [2]. - # So resolve.conf should be installed to kdump initrd as well. To prevent - # NM frome overwritting the user-configured resolve.conf in kdump initrd, - # also set dns=none for NM. - # - # Note: - # 1. When resolv.conf is managed by systemd-resolved.service, it could also be a - # symbolic link. So exclude this case by teling if systemd-resolved is enabled. - # - # 2. It's harmless to blindly copy /etc/resolve.conf to the initrd because - # by default in initramfs this file will be overwritten by - # NetworkManager. If user manages it via a symbolic link, it's still - # preserved because NM won't touch a symbolic link file. - # - # [1] https://bugzilla.gnome.org/show_bug.cgi?id=690404 - # [2] https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/manually-configuring-the-etc-resolv-conf-file_configuring-and-managing-networking - systemctl -q is-enabled systemd-resolved 2> /dev/null && return 0 - inst "$_resolv_conf" - if NetworkManager --print-config | grep -qs "^dns=none"; then - printf "[main]\ndns=none\n" > "${initdir}/${_nm_conf_dir}"/90-dns-none.conf - fi -} - -# Setup dracut to bring up network interface that enable -# initramfs accessing giving destination -kdump_install_net() { - local _netifs - - _netifs=$(_get_kdump_netifs) - if [[ -n "$_netifs" ]]; then - kdump_install_nmconnections - apply_nm_initrd_generator_timeouts - kdump_setup_znet "$_netifs" - kdump_install_nm_netif_allowlist "$_netifs" - kdump_install_nic_driver "$_netifs" - kdump_install_resolv_conf - fi -} - -# install etc/kdump/pre.d and /etc/kdump/post.d -kdump_install_pre_post_conf() { - if [[ -d /etc/kdump/pre.d ]]; then - for file in /etc/kdump/pre.d/*; do - if [[ -x $file ]]; then - dracut_install "$file" - elif [[ $file != "/etc/kdump/pre.d/*" ]]; then - echo "$file is not executable" - fi - done - fi - - if [[ -d /etc/kdump/post.d ]]; then - for file in /etc/kdump/post.d/*; do - if [[ -x $file ]]; then - dracut_install "$file" - elif [[ $file != "/etc/kdump/post.d/*" ]]; then - echo "$file is not executable" - fi - done - fi -} - -default_dump_target_install_conf() { - local _target _fstype - local _mntpoint _save_path - - is_user_configured_dump_target && return - - _save_path=$(get_bind_mount_source "$(get_save_path)") - _target=$(get_target_from_path "$_save_path") - _mntpoint=$(get_mntpoint_from_target "$_target") - - _fstype=$(get_fs_type_from_target "$_target") - if is_fs_type_nfs "$_fstype"; then - kdump_collect_netif_usage "$_target" - _fstype="nfs" - else - _target=$(kdump_get_persistent_dev "$_target") - fi - - echo "$_fstype $_target" >> "${initdir}/tmp/$$-kdump.conf" - - # don't touch the path under root mount - if [[ $_mntpoint != "/" ]]; then - _save_path=${_save_path##"$_mntpoint"} - fi - - #erase the old path line, then insert the parsed path - sed -i "/^path/d" "${initdir}/tmp/$$-kdump.conf" - echo "path $_save_path" >> "${initdir}/tmp/$$-kdump.conf" -} - -#install kdump.conf and what user specifies in kdump.conf -kdump_install_conf() { - local _opt _val _pdev - - kdump_read_conf > "${initdir}/tmp/$$-kdump.conf" - - while read -r _opt _val; do - # remove inline comments after the end of a directive. - case "$_opt" in - raw) - _pdev=$(persistent_policy="by-id" kdump_get_persistent_dev "$_val") - sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" - ;; - ext[234] | xfs | btrfs | minix | virtiofs) - _pdev=$(kdump_get_persistent_dev "$_val") - sed -i -e "s#^${_opt}[[:space:]]\+$_val#$_opt $_pdev#" "${initdir}/tmp/$$-kdump.conf" - ;; - ssh | nfs) - kdump_collect_netif_usage "$_val" - ;; - dracut_args) - if [[ $(get_dracut_args_fstype "$_val") == nfs* ]]; then - kdump_collect_netif_usage "$(get_dracut_args_target "$_val")" - fi - ;; - kdump_pre | kdump_post | extra_bins) - # shellcheck disable=SC2086 - dracut_install $_val - ;; - core_collector) - dracut_install "${_val%%[[:blank:]]*}" - ;; - esac - done <<< "$(kdump_read_conf)" - - kdump_install_pre_post_conf - - default_dump_target_install_conf - - kdump_configure_fence_kdump "${initdir}/tmp/$$-kdump.conf" - inst "${initdir}/tmp/$$-kdump.conf" "/etc/kdump.conf" - rm -f "${initdir}/tmp/$$-kdump.conf" -} - -# Default sysctl parameters should suffice for kdump kernel. -# Remove custom configurations sysctl.conf & sysctl.d/* -remove_sysctl_conf() { - - # As custom configurations like vm.min_free_kbytes can lead - # to OOM issues in kdump kernel, avoid them - rm -f "${initdir}/etc/sysctl.conf" - rm -rf "${initdir}/etc/sysctl.d" - rm -rf "${initdir}/run/sysctl.d" - rm -rf "${initdir}/usr/lib/sysctl.d" -} - -kdump_iscsi_get_rec_val() { - - local result - - # The open-iscsi 742 release changed to using flat files in - # /var/lib/iscsi. - - result=$(/sbin/iscsiadm --show -m session -r "$1" | grep "^${2} = ") - result=${result##* = } - echo "$result" -} - -kdump_get_iscsi_initiator() { - local _initiator - local initiator_conf="/etc/iscsi/initiatorname.iscsi" - - [[ -f $initiator_conf ]] || return 1 - - while read -r _initiator; do - [[ -z ${_initiator%%#*} ]] && continue # Skip comment lines - - case $_initiator in - InitiatorName=*) - initiator=${_initiator#InitiatorName=} - echo "rd.iscsi.initiator=${initiator}" - return 0 - ;; - *) ;; - esac - done < ${initiator_conf} - - return 1 -} - -# Figure out iBFT session according to session type -is_ibft() { - [[ "$(kdump_iscsi_get_rec_val "$1" "node.discovery_type")" == fw ]] -} - -kdump_setup_iscsi_device() { - local path=$1 - local tgt_name - local tgt_ipaddr - local username - local password - local userpwd_str - local username_in - local password_in - local userpwd_in_str - local netroot_str - local initiator_str - local netroot_conf="${initdir}/etc/cmdline.d/50iscsi.conf" - local initiator_conf="/etc/iscsi/initiatorname.iscsi" - - dinfo "Found iscsi component $1" - - # Check once before getting explicit values, so we can bail out early, - # e.g. in case of pure-hardware(all-offload) iscsi. - if ! /sbin/iscsiadm -m session -r "$path" &> /dev/null; then - return 1 - fi - - if is_ibft "$path"; then - return - fi - - # Remove software iscsi cmdline generated by 95iscsi, - # and let kdump regenerate here. - rm -f "${initdir}/etc/cmdline.d/95iscsi.conf" - - tgt_name=$(kdump_iscsi_get_rec_val "$path" "node.name") - tgt_ipaddr=$(kdump_iscsi_get_rec_val "$path" "node.conn\[0\].address") - - # get and set username and password details - username=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username") - [[ $username == "" ]] && username="" - password=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password") - [[ $password == "" ]] && password="" - username_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.username_in") - [[ -n $username ]] && userpwd_str="$username:$password" - - # get and set incoming username and password details - [[ $username_in == "" ]] && username_in="" - password_in=$(kdump_iscsi_get_rec_val "$path" "node.session.auth.password_in") - [[ $password_in == "" ]] && password_in="" - - [[ -n $username_in ]] && userpwd_in_str=":$username_in:$password_in" - - kdump_collect_netif_usage "$tgt_ipaddr" - - # prepare netroot= command line - # FIXME: Do we need to parse and set other parameters like protocol, port - # iscsi_iface_name, netdev_name, LUN etc. - - if is_ipv6_address "$tgt_ipaddr"; then - tgt_ipaddr="[$tgt_ipaddr]" - fi - netroot_str="netroot=iscsi:${userpwd_str}${userpwd_in_str}@$tgt_ipaddr::::$tgt_name" - - [[ -f $netroot_conf ]] || touch "$netroot_conf" - - # If netroot target does not exist already, append. - if ! grep -q "$netroot_str" "$netroot_conf"; then - echo "$netroot_str" >> "$netroot_conf" - dinfo "Appended $netroot_str to $netroot_conf" - fi - - # Setup initator - if ! initiator_str=$(kdump_get_iscsi_initiator); then - derror "Failed to get initiator name" - return 1 - fi - - # If initiator details do not exist already, append. - if ! grep -q "$initiator_str" "$netroot_conf"; then - echo "$initiator_str" >> "$netroot_conf" - dinfo "Appended $initiator_str to $netroot_conf" - fi -} - -kdump_check_iscsi_targets() { - # If our prerequisites are not met, fail anyways. - type -P iscsistart > /dev/null || return 1 - - kdump_check_setup_iscsi() { - local _dev - _dev=$1 - - [[ -L /sys/dev/block/$_dev ]] || return - cd "$(readlink -f "/sys/dev/block/$_dev")" || return 1 - until [[ -d sys || -d iscsi_session ]]; do - cd .. - done - [[ -d iscsi_session ]] && kdump_setup_iscsi_device "$PWD" - } - - [[ $hostonly ]] || [[ $mount_needs ]] && { - for_each_host_dev_and_slaves_all kdump_check_setup_iscsi - } -} - -# hostname -a is deprecated, do it by ourself -get_alias() { - local ips - local entries - local alias_set - - ips=$(hostname -I) - for ip in $ips; do - # in /etc/hosts, alias can come at the 2nd column - if entries=$(grep "$ip" /etc/hosts | awk '{ $1=""; print $0 }'); then - alias_set="$alias_set $entries" - fi - done - - echo "$alias_set" -} - -is_localhost() { - local hostnames - local shortnames - local aliasname - local nodename=$1 - - hostnames=$(hostname -A) - shortnames=$(hostname -A -s) - aliasname=$(get_alias) - hostnames="$hostnames $shortnames $aliasname" - - for name in ${hostnames}; do - if [[ $name == "$nodename" ]]; then - return 0 - fi - done - return 1 -} - -# retrieves fence_kdump nodes from Pacemaker cluster configuration -get_pcs_fence_kdump_nodes() { - local nodes - - pcs cluster sync > /dev/null 2>&1 && pcs cluster cib-upgrade > /dev/null 2>&1 - # get cluster nodes from cluster cib, get interface and ip address - nodelist=$(pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -) - - # nodelist is formed as 'uname="node1" uname="node2" ... uname="nodeX"' - # we need to convert each to node1, node2 ... nodeX in each iteration - for node in ${nodelist}; do - # convert $node from 'uname="nodeX"' to 'nodeX' - eval "$node" - nodename="$uname" - # Skip its own node name - if is_localhost "$nodename"; then - continue - fi - nodes="$nodes $nodename" - done - - echo "$nodes" -} - -# retrieves fence_kdump args from config file -get_pcs_fence_kdump_args() { - if [[ -f $FENCE_KDUMP_CONFIG_FILE ]]; then - . "$FENCE_KDUMP_CONFIG_FILE" - echo "$FENCE_KDUMP_OPTS" - fi -} - -get_generic_fence_kdump_nodes() { - local filtered - local nodes - - nodes=$(kdump_get_conf_val "fence_kdump_nodes") - for node in ${nodes}; do - # Skip its own node name - if is_localhost "$node"; then - continue - fi - filtered="$filtered $node" - done - echo "$filtered" -} - -# setup fence_kdump in cluster -# setup proper network and install needed files -kdump_configure_fence_kdump() { - local kdump_cfg_file=$1 - local nodes - local args - - if is_generic_fence_kdump; then - nodes=$(get_generic_fence_kdump_nodes) - - elif is_pcs_fence_kdump; then - nodes=$(get_pcs_fence_kdump_nodes) - - # set appropriate options in kdump.conf - echo "fence_kdump_nodes $nodes" >> "${kdump_cfg_file}" - - args=$(get_pcs_fence_kdump_args) - if [[ -n $args ]]; then - echo "fence_kdump_args $args" >> "${kdump_cfg_file}" - fi - - else - # fence_kdump not configured - return 1 - fi - - # setup network for each node - for node in ${nodes}; do - kdump_collect_netif_usage "$node" - done - - dracut_install /etc/hosts - dracut_install /etc/nsswitch.conf - dracut_install "$FENCE_KDUMP_SEND" -} - -# Install a random seed used to feed /dev/urandom -# By the time kdump service starts, /dev/uramdom is already fed by systemd -kdump_install_random_seed() { - local poolsize - - poolsize=$(< /proc/sys/kernel/random/poolsize) - - if [[ ! -d "${initdir}/var/lib/" ]]; then - mkdir -p "${initdir}/var/lib/" - fi - - dd if=/dev/urandom of="${initdir}/var/lib/random-seed" \ - bs="$poolsize" count=1 2> /dev/null -} - -kdump_install_systemd_conf() { - # Kdump turns out to require longer default systemd mount timeout - # than 1st kernel(90s by default), we use default 300s for kdump. - if ! grep -q -r "^[[:space:]]*DefaultTimeoutStartSec=" "${initdir}/etc/systemd/system.conf"*; then - mkdir -p "${initdir}/etc/systemd/system.conf.d" - echo "[Manager]" > "${initdir}/etc/systemd/system.conf.d/kdump.conf" - echo "DefaultTimeoutStartSec=300s" >> "${initdir}/etc/systemd/system.conf.d/kdump.conf" - fi - - # Forward logs to console directly, and don't read Kmsg, this avoids - # unneccessary memory consumption and make console output more useful. - # Only do so for non fadump image. - mkdir -p "${initdir}/etc/systemd/journald.conf.d" - echo "[Journal]" > "${initdir}/etc/systemd/journald.conf.d/kdump.conf" - echo "Storage=volatile" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf" - echo "ReadKMsg=no" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf" - echo "ForwardToConsole=yes" >> "${initdir}/etc/systemd/journald.conf.d/kdump.conf" -} - -remove_cpu_online_rule() { - local file=${initdir}/usr/lib/udev/rules.d/40-redhat.rules - - if [[ -f $file ]]; then - sed -i '/SUBSYSTEM=="cpu"/d' "$file" - fi -} - -install() { - declare -A unique_netifs ipv4_usage ipv6_usage - local arch - - kdump_module_init - kdump_install_conf - remove_sysctl_conf - - # Onlining secondary cpus breaks kdump completely on KVM on Power hosts - # Though we use maxcpus=1 by default but 40-redhat.rules will bring up all - # possible cpus by default. (rhbz1270174 rhbz1266322) - # Thus before we get the kernel fix and the systemd rule fix let's remove - # the cpu online rule in kdump initramfs. - arch=$(uname -m) - if [[ "$arch" = "ppc64le" ]] || [[ "$arch" = "ppc64" ]]; then - remove_cpu_online_rule - fi - - if is_ssh_dump_target; then - kdump_install_random_seed - fi - dracut_install -o /etc/adjtime /etc/localtime - inst "$moddir/monitor_dd_progress.sh" "/kdumpscripts/monitor_dd_progress.sh" - inst "/bin/dd" "/bin/dd" - inst "/bin/tail" "/bin/tail" - inst "/bin/date" "/bin/date" - inst "/bin/sync" "/bin/sync" - inst "/bin/cut" "/bin/cut" - inst "/bin/head" "/bin/head" - inst "/bin/awk" "/bin/awk" - inst "/bin/sed" "/bin/sed" - inst "/bin/stat" "/bin/stat" - inst "/sbin/makedumpfile" "/sbin/makedumpfile" - inst "/sbin/vmcore-dmesg" "/sbin/vmcore-dmesg" - inst "/usr/bin/printf" "/sbin/printf" - inst "/usr/bin/logger" "/sbin/logger" - inst "/usr/bin/chmod" "/sbin/chmod" - inst "/lib/kdump/kdump-lib-initramfs.sh" "/lib/kdump-lib-initramfs.sh" - inst "/lib/kdump/kdump-logger.sh" "/lib/kdump-logger.sh" - inst "$moddir/kdump.sh" "/usr/bin/kdump.sh" - inst "$moddir/kdump-capture.service" "$systemdsystemunitdir/kdump-capture.service" - systemctl -q --root "$initdir" add-wants initrd.target kdump-capture.service - # Replace existing emergency service and emergency target - cp "$moddir/kdump-emergency.service" "$initdir/$systemdsystemunitdir/emergency.service" - cp "$moddir/kdump-emergency.target" "$initdir/$systemdsystemunitdir/emergency.target" - # Also redirect dracut-emergency to kdump error handler - ln_r "$systemdsystemunitdir/emergency.service" "$systemdsystemunitdir/dracut-emergency.service" - - # Check for all the devices and if any device is iscsi, bring up iscsi - # target. Ideally all this should be pushed into dracut iscsi module - # at some point of time. - kdump_check_iscsi_targets - - kdump_install_systemd_conf - - # nfs/ssh dump will need to get host ip in second kernel and need to call 'ip' tool, see get_host_ip for more detail - if is_nfs_dump_target || is_ssh_dump_target; then - inst "ip" - fi - - kdump_install_net - - # For the lvm type target under kdump, in /etc/lvm/lvm.conf we can - # safely replace "reserved_memory=XXXX"(default value is 8192) with - # "reserved_memory=1024" to lower memory pressure under kdump. We do - # it unconditionally here, if "/etc/lvm/lvm.conf" doesn't exist, it - # actually does nothing. - sed -i -e \ - 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ - "${initdir}/etc/lvm/lvm.conf" &> /dev/null - - # Skip initrd-cleanup.service and initrd-parse-etc.service becasue we don't - # need to switch root. Instead of removing them, we use ConditionPathExists - # to check if /proc/vmcore exists to determine if we are in kdump. - sed -i '/\[Unit\]/a ConditionPathExists=!\/proc\/vmcore' \ - "${initdir}/${systemdsystemunitdir}/initrd-cleanup.service" &> /dev/null - - sed -i '/\[Unit\]/a ConditionPathExists=!\/proc\/vmcore' \ - "${initdir}/${systemdsystemunitdir}/initrd-parse-etc.service" &> /dev/null - - # Save more memory by dropping switch root capability - dracut_no_switch_root -} diff --git a/dracut-monitor_dd_progress.sh b/dracut-monitor_dd_progress.sh deleted file mode 100644 index e139d33..0000000 --- a/dracut-monitor_dd_progress.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -SRC_FILE_MB=$1 - -while true -do - DD_PID=`pidof dd` - if [ -n "$DD_PID" ]; then - break - fi -done - -while true -do - sleep 5 - if [ ! -d /proc/$DD_PID ]; then - break - fi - - kill -s USR1 $DD_PID - CURRENT_SIZE=`tail -n 1 /tmp/dd_progress_file | sed "s/[^0-9].*//g"` - [ -n "$CURRENT_SIZE" ] && { - CURRENT_MB=$(($CURRENT_SIZE / 1048576)) - echo -e "Copied $CURRENT_MB MB / $SRC_FILE_MB MB\r" - } -done - -rm -f /tmp/dd_progress_file diff --git a/early-kdump-howto.txt b/early-kdump-howto.txt deleted file mode 100644 index 68b23c7..0000000 --- a/early-kdump-howto.txt +++ /dev/null @@ -1,95 +0,0 @@ -Early Kdump HOWTO - -Introduction ------------- - -Early kdump is a mechanism to make kdump operational earlier than normal kdump -service. The kdump service starts early enough for general crash cases, but -there are some cases where it has no chance to make kdump operational in boot -sequence, such as detecting devices and starting early services. If you hit -such a case, early kdump may allow you to get more information of it. - -Early kdump is implemented as a dracut module. It adds a kernel (vmlinuz) and -initramfs for kdump to your system's initramfs in order to load them as early -as possible. After that, if you provide "rd.earlykdump" in kernel command line, -then in the initramfs, early kdump will load those files like the normal kdump -service. This is disabled by default. - -For the normal kdump service, it can check whether the early kdump has loaded -the crash kernel and initramfs. It has no conflict with the early kdump. - -How to configure early kdump ----------------------------- - -We assume if you're reading this document, you should already have kexec-tools -installed. - -You can rebuild the initramfs with earlykdump support with below steps: - -1. start kdump service to make sure kdump initramfs is created. - - # systemctl start kdump - - NOTE: If a crash occurs during boot process, early kdump captures a vmcore - and reboot the system by default, so the system might go into crash loop. - You can avoid such a crash loop by adding the following settings, which - power off the system after dump capturing, to kdump.conf in advance: - - final_action poweroff - failure_action poweroff - - For the failure_action, you can choose anything other than "reboot". - -2. rebuild system initramfs with earlykdump support. - - # dracut --force --add earlykdump - - NOTE: Recommend to backup the original system initramfs before performing - this step to put it back if something happens during boot-up. - -3. add rd.earlykdump in grub kernel command line. - -After making said changes, reboot your system to take effect. Of course, if you -want to disable early kdump, you can simply remove "rd.earlykdump" from kernel -boot parameters in grub, and reboot system like above. - -Once the boot is completed, you can check the status of the early kdump support -on the command prompt: - - # journalctl -b | grep early-kdump - -Then, you will see some useful logs, for example: - -- if early kdump is successful. - -Mar 09 09:57:56 localhost dracut-cmdline[190]: early-kdump is enabled. -Mar 09 09:57:56 localhost dracut-cmdline[190]: kexec: loaded early-kdump kernel - -- if early kdump is disabled. - -Mar 09 10:02:47 localhost dracut-cmdline[189]: early-kdump is disabled. - -Notes ------ - -- The size of early kdump initramfs will be large because it includes vmlinuz - and kdump initramfs. - -- Early kdump inherits the settings of normal kdump, so any changes that - caused normal kdump rebuilding also require rebuilding the system initramfs - to make sure that the changes take effect for early kdump. Therefore, after - the rebuilding of kdump initramfs is completed, provide a prompt message to - tell the fact. - -- If you install an updated kernel and reboot the system with it, the early - kdump will be disabled by default. To enable it with the new kernel, you - need to take the above steps again. - -Limitation ----------- - -- At present, early kdump doesn't support fadump. - -- Early kdump loads a crash kernel and initramfs at the beginning of the - process in system's initramfs, so a crash at earlier than that (e.g. in - kernel initialization) cannot be captured even with the early kdump. diff --git a/fadump-howto.txt b/fadump-howto.txt deleted file mode 100644 index 2fe76cf..0000000 --- a/fadump-howto.txt +++ /dev/null @@ -1,359 +0,0 @@ -Firmware assisted dump (fadump) HOWTO - -Introduction - -Firmware assisted dump is a new feature in the 3.4 mainline kernel supported -only on powerpc architecture. The goal of firmware-assisted dump is to enable -the dump of a crashed system, and to do so from a fully-reset system, and to -minimize the total elapsed time until the system is back in production use. A -complete documentation on implementation can be found at -Documentation/powerpc/firmware-assisted-dump.txt in upstream linux kernel tree -from 3.4 version and above. - -Please note that the firmware-assisted dump feature is only available on Power6 -and above systems with recent firmware versions. - -Overview - -Fadump - -Fadump is a robust kernel crash dumping mechanism to get reliable kernel crash -dump with assistance from firmware. This approach does not use kexec, instead -firmware assists in booting the kdump kernel while preserving memory contents. -Unlike kdump, the system is fully reset, and loaded with a fresh copy of the -kernel. In particular, PCI and I/O devices are reinitialized and are in a -clean, consistent state. This second kernel, often called a capture kernel, -boots with very little memory and captures the dump image. - -The first kernel registers the sections of memory with the Power firmware for -dump preservation during OS initialization. These registered sections of memory -are reserved by the first kernel during early boot. When a system crashes, the -Power firmware fully resets the system, preserves all the system memory -contents, save the low memory (boot memory of size larger of 5% of system -RAM or 256MB) of RAM to the previous registered region. It will also save -system registers, and hardware PTE's. - -Fadump is supported only on ppc64 platform. The standard kernel and capture -kernel are one and the same on ppc64. - -If you're reading this document, you should already have kexec-tools -installed. If not, you install it via the following command: - - # dnf install kexec-tools - -Fadump Operational Flow: - -Like kdump, fadump also exports the ELF formatted kernel crash dump through -/proc/vmcore. Hence existing kdump infrastructure can be used to capture fadump -vmcore. The idea is to keep the functionality transparent to end user. From -user perspective there is no change in the way kdump init script works. - -However, unlike kdump, fadump does not pre-load kdump kernel and initrd into -reserved memory, instead it always uses default OS initrd during second boot -after crash. Hence, for fadump, we rebuild the new kdump initrd and replace it -with default initrd. Before replacing existing default initrd we take a backup -of original default initrd for user's reference. The dracut package has been -enhanced to rebuild the default initrd with vmcore capture steps. The initrd -image is rebuilt as per the configuration in /etc/kdump.conf file. - -The control flow of fadump works as follows: -01. System panics. -02. At the crash, kernel informs power firmware that kernel has crashed. -03. Firmware takes the control and reboots the entire system preserving - only the memory (resets all other devices). -04. The reboot follows the normal booting process (non-kexec). -05. The boot loader loads the default kernel and initrd from /boot -06. The default initrd loads and runs /init -07. dracut-kdump.sh script present in fadump aware default initrd checks if - '/proc/device-tree/rtas/ibm,kernel-dump' file exists before executing - steps to capture vmcore. - (This check will help to bypass the vmcore capture steps during normal boot - process.) -09. Captures dump according to /etc/kdump.conf -10. Is dump capture successful (yes goto 12, no goto 11) -11. Perform the failure action specified in /etc/kdump.conf - (The default failure action is reboot, if unspecified) -12. Perform the final action specified in /etc/kdump.conf - (The default final action is reboot, if unspecified) - - -How to configure fadump: - -Again, we assume if you're reading this document, you should already have -kexec-tools installed. If not, you install it via the following command: - - # dnf install kexec-tools - -Make the kernel to be configured with FADump as the default boot entry, if -it isn't already: - - # grubby --set-default=/boot/vmlinuz- - -Boot into the kernel to be configured for FADump. To be able to do much of -anything interesting in the way of debug analysis, you'll also need to install -the kernel-debuginfo package, of the same arch as your running kernel, and the -crash utility: - - # dnf --enablerepo=\*debuginfo install kernel-debuginfo.$(uname -m) crash - -Next up, we can enable firmware assisted dump and reserve the memory for boot -memory preservation as specified in in the table of 'FADump Memory Requirements' -section: - - # kdumpctl reset-crashkernel --fadump=on - -Alternatively, you can use grubby to reserve custom amount of memory: - - # grubby --args="fadump=on crashkernel=6G" --update-kernel=/boot/vmlinuz-`uname -r` - -By default, FADump reserved memory will be initialized as CMA area to make the -memory available through CMA allocator on the production kernel. We can opt out -of this, making reserved memory unavailable to production kernel, by booting the -linux kernel with 'fadump=nocma' instead of 'fadump=on': - - # kdumpctl reset-crashkernel --fadump=nocma - -The term 'boot memory' means size of the low memory chunk that is required for -a kernel to boot successfully when booted with restricted memory. By default, -the boot memory size will be the larger of 5% of system RAM or 256MB. -Alternatively, user can also specify boot memory size through boot parameter -'fadump_reserve_mem=' which will override the default calculated size. Use this -option if default boot memory size is not sufficient for second kernel to boot -successfully. - -After making said changes, reboot your system, so that the specified memory is -reserved and left untouched by the normal system. Take note that the output of -'free -m' will show X MB less memory than without this parameter, which is -expected. If you see OOM (Out Of Memory) error messages while loading capture -kernel, then you should bump up the memory reservation size. - -Now that you've got that reserved memory region set up, you want to turn on -the kdump init script: - - # systemctl enable kdump.service - -Then, start up kdump as well: - - # systemctl start kdump.service - -This should turn on the firmware assisted functionality in kernel by -echo'ing 1 to /sys/kernel/fadump/registered, leaving the system ready -to capture a vmcore upon crashing. For journaling filesystems like XFS an -additional step is required to ensure bootloader does not pick the -older initrd (without vmcore capture scripts): - - * If /boot is a separate partition, run the below commands as the root user, - or as a user with CAP_SYS_ADMIN rights: - - # fsfreeze -f - # fsfreeze -u - - * If /boot is not a separate partition, reboot the system. - -After reboot check if the kdump service is up and running with: - - # systemctl status kdump.service - -To test out whether FADump is configured properly, you can force-crash your -system by echo'ing a 'c' into /proc/sysrq-trigger: - - # echo c > /proc/sysrq-trigger - -You should see some panic output, followed by the system reset and booting into -fresh copy of kernel. When default initrd loads and runs /init, vmcore should -be copied out to disk (by default, in /var/crash//vmcore), -then the system rebooted back into your normal kernel. - -Once back to your normal kernel, you can use the previously installed crash -kernel in conjunction with the previously installed kernel-debuginfo to -perform postmortem analysis: - - # crash /usr/lib/debug/lib/modules/2.6.17-1.2621.el5/vmlinux - /var/crash/2006-08-23-15:34/vmcore - - crash> bt - -and so on... - -Saving vmcore-dmesg.txt ------------------------ -Kernel log bufferes are one of the most important information available -in vmcore. Now before saving vmcore, kernel log bufferes are extracted -from /proc/vmcore and saved into a file vmcore-dmesg.txt. After -vmcore-dmesg.txt, vmcore is saved. Destination disk and directory for -vmcore-dmesg.txt is same as vmcore. Note that kernel log buffers will -not be available if dump target is raw device. - -FADump Memory Requirements: - - System Memory Recommended memory ---------------------- ---------------------- - 4 GB - 16 GB : 768 MB - 16 GB - 64 GB : 1024 MB - 64 GB - 128 GB : 2 GB - 128 GB - 1 TB : 4 GB - 1 TB - 2 TB : 6 GB - 2 TB - 4 TB : 12 GB - 4 TB - 8 TB : 20 GB - 8 TB - 16 TB : 36 GB - 16 TB - 32 TB : 64 GB - 32 TB - 64 TB : 128 GB - 64 TB & above : 180 GB - -Things to remember: - -1) The memory required to boot capture Kernel is a moving target that depends - on many factors like hardware attached to the system, kernel and modules in - use, packages installed and services enabled, there is no one-size-fits-all. - But the above recommendations are based on system memory. So, the above - recommendations for FADump come with a few assumptions, based on available - system memory, about the resources the system could have. So, please take - the recommendations with a pinch of salt and remember to try capturing dump - a few times to confirm that the system is configured successfully with dump - capturing support. - -2) Though the memory requirements for FADump seem high, this memory is not - completely set aside but made available for userspace applications to use, - through the CMA allocator. - -3) As the same initrd is used for booting production kernel as well as capture - kernel and with dump being captured in a restricted memory environment, few - optimizations (like not inclding network dracut module, disabling multipath - and such) are applied while building the initrd. In case, the production - environment needs these optimizations to be avoided, dracut_args option in - /etc/kdump.conf file could be leveraged. For example, if a user wishes for - network module to be included in the initrd, adding the below entry in - /etc/kdump.conf file and restarting kdump service would take care of it. - - dracut_args --add "network" - -4) If FADump is configured to capture vmcore to a remote dump target using SSH - or NFS protocol, the corresponding network interface '' is - renamed to 'kdump-', if it is generic (like *eth# or net#). - It happens because vmcore capture scripts in the initial RAM disk (initrd) - add the 'kdump-' prefix to the network interface name to secure persistent - naming. And as capture kernel and production kernel use the same initrd in - case of FADump, the interface name is changed for the production kernel too. - This is likely to impact network configuration setup for production kernel. - So, it is recommended to use a non-generic name for a network interface, - before setting up FADump to capture vmcore to a remote dump target based on - that network interface, to avoid running into network configuration issues. - -Dump Triggering methods: - -This section talks about the various ways, other than a Kernel Panic, in which -fadump can be triggered. The following methods assume that fadump is configured -on your system, with the scripts enabled as described in the section above. - -1) AltSysRq C - -FAdump can be triggered with the combination of the 'Alt','SysRq' and 'C' -keyboard keys. Please refer to the following link for more details: - -https://fedoraproject.org/wiki/QA/Sysrq - -In addition, on PowerPC boxes, fadump can also be triggered via Hardware -Management Console(HMC) using 'Ctrl', 'O' and 'C' keyboard keys. - -2) Kernel OOPs - -If we want to generate a dump everytime the Kernel OOPses, we can achieve this -by setting the 'Panic On OOPs' option as follows: - - # echo 1 > /proc/sys/kernel/panic_on_oops - -3) PowerPC specific methods: - -On IBM PowerPC machines, issuing a soft reset invokes the XMON debugger(if -XMON is configured). To configure XMON one needs to compile the kernel with -the CONFIG_XMON and CONFIG_XMON_DEFAULT options, or by compiling with -CONFIG_XMON and booting the kernel with xmon=on option. - -Following are the ways to remotely issue a soft reset on PowerPC boxes, which -would drop you to XMON. Pressing a 'X' (capital alphabet X) followed by an -'Enter' here will trigger the dump. - -3.1) HMC - -Hardware Management Console(HMC) available on Power4 and Power5 machines allow -partitions to be reset remotely. This is specially useful in hang situations -where the system is not accepting any keyboard inputs. - -Once you have HMC configured, the following steps will enable you to trigger -fadump via a soft reset: - -On Power4 - Using GUI - - * In the right pane, right click on the partition you wish to dump. - * Select "Operating System->Reset". - * Select "Soft Reset". - * Select "Yes". - - Using HMC Commandline - - # reset_partition -m -p -t soft - -On Power5 - Using GUI - - * In the right pane, right click on the partition you wish to dump. - * Select "Restart Partition". - * Select "Dump". - * Select "OK". - - Using HMC Commandline - - # chsysstate -m -n -o dumprestart -r lpar - -3.2) Blade Management Console for Blade Center - -To initiate a dump operation, go to Power/Restart option under "Blade Tasks" in -the Blade Management Console. Select the corresponding blade for which you want -to initate the dump and then click "Restart blade with NMI". This issues a -system reset and invokes xmon debugger. - - -Advanced Setups & Failure action: - -Kdump and fadump exhibit similar behavior in terms of setup & failure action. -For fadump advanced setup related information see section "Advanced Setups" in -"kexec-kdump-howto.txt" document. Refer to "Failure action" section in "kexec- -kdump-howto.txt" document for fadump failure action related information. - -Compression and filtering - -Refer "Compression and filtering" section in "kexec-kdump-howto.txt" document. -Compression and filtering are same for kdump & fadump. - - -Notes on rootfs mount: -Dracut is designed to mount rootfs by default. If rootfs mounting fails it -will refuse to go on. So fadump leaves rootfs mounting to dracut currently. -We make the assumtion that proper root= cmdline is being passed to dracut -initramfs for the time being. If you need modify "KDUMP_COMMANDLINE=" in -/etc/sysconfig/kdump, you will need to make sure that appropriate root= -options are copied from /proc/cmdline. In general it is best to append -command line options using "KDUMP_COMMANDLINE_APPEND=" instead of replacing -the original command line completely. - -How to disable FADump: - -Remove "fadump=on"/"fadump=nocma" from kernel cmdline parameters OR replace -it with "fadump=off" kernel cmdline parameter: - - # grubby --update-kernel=/boot/vmlinuz-`uname -r` --remove-args="fadump=on" -or - # grubby --update-kernel=/boot/vmlinuz-`uname -r` --remove-args="fadump=nocma" -OR - # grubby --update-kernel=/boot/vmlinuz-`uname -r` --args="fadump=off" - -Remove "crashkernel=" from kernel cmdline parameters: - - # grubby --update-kernel=/boot/vmlinuz-`uname -r` --remove-args="crashkernel" - -If KDump is to be used as the dump capturing mechanism, reset the crashkernel parameter: - - # kdumpctl reset-crashkernel --fadump=off - -Reboot the system for the settings to take effect. diff --git a/gen-kdump-conf.sh b/gen-kdump-conf.sh deleted file mode 100755 index a8e7fdd..0000000 --- a/gen-kdump-conf.sh +++ /dev/null @@ -1,225 +0,0 @@ -#!/bin/bash -# $1: target arch - -SED_EXP="" - -generate() -{ - sed "$SED_EXP" << EOF -# This file contains a series of commands to perform (in order) in the kdump -# kernel after a kernel crash in the crash kernel(1st kernel) has happened. -# -# Directives in this file are only applicable to the kdump initramfs, and have -# no effect once the root filesystem is mounted and the normal init scripts are -# processed. -# -# Currently, only one dump target and path can be specified. If the dumping to -# the configured target fails, the failure action which can be configured via -# the "failure_action" directive will be performed. -# -# Supported options: -# -# auto_reset_crashkernel -# - whether to reset kernel crashkernel to new default value -# or not when kexec-tools updates the default crashkernel value and -# existing kernels using the old default kernel crashkernel value. -# The default value is yes. -# -# raw -# - Will dd /proc/vmcore into . -# Use persistent device names for partition devices, -# such as /dev/vg/. -# -# nfs -# - Will mount nfs to , and copy /proc/vmcore to -# //%HOST-%DATE/, supports DNS. -# -# ssh -# - Will save /proc/vmcore to :/%HOST-%DATE/, -# supports DNS. -# NOTE: make sure the user has write permissions on the server. -# -# sshkey -# - Will use the sshkey to do ssh dump. -# Specify the path of the ssh key to use when dumping -# via ssh. The default value is /root/.ssh/kdump_id_rsa. -# -# -# - Will mount -t , and copy -# /proc/vmcore to //%HOST_IP-%DATE/. -# NOTE: can be a device node, label or uuid. -# It's recommended to use persistent device names -# such as /dev/vg/. -# Otherwise it's suggested to use label or uuid. -# Supported fs types: ext[234], xfs, btrfs, minix, virtiofs -# -# path -# - "path" represents the file system path in which vmcore -# will be saved. If a dump target is specified in -# kdump.conf, then "path" is relative to the specified -# dump target. -# -# Interpretation of "path" changes a bit if the user didn't -# specify any dump target explicitly in kdump.conf. In this -# case, "path" represents the absolute path from root. The -# dump target and adjusted path are arrived at automatically -# depending on what's mounted in the current system. -# -# Ignored for raw device dumps. If unset, will use the default -# "/var/crash". -# -# core_collector -# - This allows you to specify the command to copy -# the vmcore. The default is makedumpfile, which on -# some architectures can drastically reduce vmcore size. -# See /sbin/makedumpfile --help for a list of options. -# Note that the -i and -g options are not needed here, -# as the initrd will automatically be populated with a -# config file appropriate for the running kernel. -# The default core_collector for raw/ssh dump is: -# "makedumpfile -F -l --message-level 7 -d 31". -# The default core_collector for other targets is: -# "makedumpfile -l --message-level 7 -d 31". -# -# "makedumpfile -F" will create a flattened vmcore. -# You need to use "makedumpfile -R" to rearrange the dump data to -# a normal dumpfile readable with analysis tools. For example: -# "makedumpfile -R vmcore < vmcore.flat". -# -# For core_collector format details, you can refer to -# kexec-kdump-howto.txt or kdump.conf manpage. -# -# kdump_post -# - This directive allows you to run a executable binary -# or script after the vmcore dump process terminates. -# The exit status of the current dump process is fed to -# the executable binary or script as its first argument. -# All files under /etc/kdump/post.d are collectively sorted -# and executed in lexical order, before binary or script -# specified kdump_post parameter is executed. -# -# kdump_pre -# - Works like the "kdump_post" directive, but instead of running -# after the dump process, runs immediately before it. -# Exit status of this binary is interpreted as follows: -# 0 - continue with dump process as usual -# non 0 - run the final action (reboot/poweroff/halt) -# All files under /etc/kdump/pre.d are collectively sorted and -# executed in lexical order, after binary or script specified -# kdump_pre parameter is executed. -# Even if the binary or script in /etc/kdump/pre.d directory -# returns non 0 exit status, the processing is continued. -# -# extra_bins -# - This directive allows you to specify additional binaries or -# shell scripts to be included in the kdump initrd. -# Generally they are useful in conjunction with a kdump_post -# or kdump_pre binary or script which depends on these extra_bins. -# -# extra_modules -# - This directive allows you to specify extra kernel modules -# that you want to be loaded in the kdump initrd. -# Multiple modules can be listed, separated by spaces, and any -# dependent modules will automatically be included. -# -# failure_action -# - Action to perform in case dumping fails. -# reboot: Reboot the system. -# halt: Halt the system. -# poweroff: Power down the system. -# shell: Drop to a bash shell. -# Exiting the shell reboots the system by default, -# or perform "final_action". -# dump_to_rootfs: Dump vmcore to rootfs from initramfs context and -# reboot by default or perform "final_action". -# Useful when non-root dump target is specified. -# The default option is "reboot". -# -# default -# - Same as the "failure_action" directive above, but this directive -# is obsolete and will be removed in the future. -# -# final_action -# - Action to perform in case dumping succeeds. Also performed -# when "shell" or "dump_to_rootfs" failure action finishes. -# Each action is same as the "failure_action" directive above. -# The default is "reboot". -# -# force_rebuild <0 | 1> -# - By default, kdump initrd will only be rebuilt when necessary. -# Specify 1 to force rebuilding kdump initrd every time when kdump -# service starts. -# -# force_no_rebuild <0 | 1> -# - By default, kdump initrd will be rebuilt when necessary. -# Specify 1 to bypass rebuilding of kdump initrd. -# -# force_no_rebuild and force_rebuild options are mutually -# exclusive and they should not be set to 1 simultaneously. -# -# dracut_args -# - Pass extra dracut options when rebuilding kdump initrd. -# -# fence_kdump_args -# - Command line arguments for fence_kdump_send (it can contain -# all valid arguments except hosts to send notification to). -# -# fence_kdump_nodes -# - List of cluster node(s) except localhost, separated by spaces, -# to send fence_kdump notifications to. -# (this option is mandatory to enable fence_kdump). -# - -#raw /dev/vg/lv_kdump -#ext4 /dev/vg/lv_kdump -#ext4 LABEL=/boot -#ext4 UUID=03138356-5e61-4ab3-b58e-27507ac41937 -#virtiofs myfs -#nfs my.server.com:/export/tmp -#nfs [2001:db8::1:2:3:4]:/export/tmp -#ssh user@my.server.com -#ssh user@2001:db8::1:2:3:4 -#sshkey /root/.ssh/kdump_id_rsa -auto_reset_crashkernel yes -path /var/crash -core_collector makedumpfile -l --message-level 7 -d 31 -#core_collector scp -#kdump_post /var/crash/scripts/kdump-post.sh -#kdump_pre /var/crash/scripts/kdump-pre.sh -#extra_bins /usr/bin/lftp -#extra_modules gfs2 -#failure_action shell -#force_rebuild 1 -#force_no_rebuild 1 -#dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3" -#fence_kdump_args -p 7410 -f auto -c 0 -i 10 -#fence_kdump_nodes node1 node2 -EOF -} - -update_param() -{ - SED_EXP="${SED_EXP}s/^$1.*$/$1 $2/;" -} - -case "$1" in -aarch64) ;; - -i386) ;; - -ppc64) ;; - -ppc64le) ;; - -s390x) - update_param core_collector \ - "makedumpfile -c --message-level 7 -d 31" - ;; -x86_64) ;; - -*) - echo "Warning: Unknown architecture '$1', using default kdump.conf template." >&2 - ;; -esac - -generate diff --git a/gen-kdump-sysconfig.sh b/gen-kdump-sysconfig.sh deleted file mode 100755 index 78b0bb7..0000000 --- a/gen-kdump-sysconfig.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash -# $1: target arch - -SED_EXP="" - -generate() -{ - sed "$SED_EXP" << EOF -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug quiet log_buf_len swiotlb cma hugetlb_cma ignition.firstboot" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 reset_devices novmcoredd cma=0 hugetlb_cma=0" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" - -# 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) -# -# 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 -# -# Logging levels: no logging(0), error(1),warn(2),info(3),debug(4) -# -# KDUMP_STDLOGLVL=3 -# KDUMP_SYSLOGLVL=0 -# KDUMP_KMSGLOGLVL=0 -EOF -} - -update_param() -{ - SED_EXP="${SED_EXP}s/^$1=.*$/$1=\"$2\"/;" -} - -case "$1" in -aarch64) - update_param KEXEC_ARGS "-s" - update_param KDUMP_COMMANDLINE_APPEND \ - "irqpoll nr_cpus=1 reset_devices cgroup_disable=memory udev.children-max=2 panic=10 swiotlb=noforce novmcoredd cma=0 hugetlb_cma=0" - ;; -i386) - update_param KDUMP_COMMANDLINE_APPEND \ - "irqpoll nr_cpus=1 reset_devices numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd cma=0 hugetlb_cma=0" - ;; -ppc64) - update_param KEXEC_ARGS "--dt-no-old-root" - update_param KDUMP_COMMANDLINE_REMOVE \ - "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" - update_param KDUMP_COMMANDLINE_APPEND \ - "irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" - ;; -ppc64le) - update_param KEXEC_ARGS "--dt-no-old-root -s" - update_param KDUMP_COMMANDLINE_REMOVE \ - "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb hugetlb_cma ignition.firstboot" - update_param KDUMP_COMMANDLINE_APPEND \ - "irqpoll nr_cpus=1 noirqdistrib reset_devices cgroup_disable=memory numa=off udev.children-max=2 ehea.use_mcs=0 panic=10 kvm_cma_resv_ratio=0 transparent_hugepage=never novmcoredd hugetlb_cma=0" - ;; -s390x) - update_param KEXEC_ARGS "-s" - update_param KDUMP_COMMANDLINE_REMOVE \ - "hugepages hugepagesz slub_debug quiet log_buf_len swiotlb vmcp_cma cma hugetlb_cma prot_virt ignition.firstboot zfcp.allow_lun_scan" - update_param KDUMP_COMMANDLINE_APPEND \ - "nr_cpus=1 cgroup_disable=memory numa=off udev.children-max=2 panic=10 transparent_hugepage=never novmcoredd vmcp_cma=0 cma=0 hugetlb_cma=0" - ;; -x86_64) - update_param KEXEC_ARGS "-s" - update_param 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 cma=0 hugetlb_cma=0" - ;; -*) - echo "Warning: Unknown architecture '$1', using default sysconfig template." >&2 - ;; -esac - -generate diff --git a/kdump-dep-generator.sh b/kdump-dep-generator.sh deleted file mode 100644 index 70ae621..0000000 --- a/kdump-dep-generator.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -# More details about systemd generator: -# http://www.freedesktop.org/wiki/Software/systemd/Generators/ - -. /usr/lib/kdump/kdump-lib-initramfs.sh -. /usr/lib/kdump/kdump-logger.sh - -# If invokded with no arguments for testing purpose, output to /tmp to -# avoid overriding the existing. -dest_dir="/tmp" - -if [ -n "$1" ]; then - dest_dir=$1 -fi - -systemd_dir=/usr/lib/systemd/system -kdump_wants=$dest_dir/kdump.service.wants - -if is_ssh_dump_target; then - mkdir -p $kdump_wants - ln -sf $systemd_dir/network-online.target $kdump_wants/ -fi diff --git a/kdump-in-cluster-environment.txt b/kdump-in-cluster-environment.txt deleted file mode 100644 index de1eb5e..0000000 --- a/kdump-in-cluster-environment.txt +++ /dev/null @@ -1,91 +0,0 @@ -Kdump-in-cluster-environment HOWTO - -Introduction - -Kdump is a kexec based crash dumping mechansim for Linux. This docuement -illustrate how to configure kdump in cluster environment to allow the kdump -crash recovery service complete without being preempted by traditional power -fencing methods. - -Overview - -Kexec/Kdump - -Details about Kexec/Kdump are available in Kexec-Kdump-howto file and will not -be described here. - -fence_kdump - -fence_kdump is an I/O fencing agent to be used with the kdump crash recovery -service. When the fence_kdump agent is invoked, it will listen for a message -from the failed node that acknowledges that the failed node is executing the -kdump crash kernel. Note that fence_kdump is not a replacement for traditional -fencing methods. The fence_kdump agent can only detect that a node has entered -the kdump crash recovery service. This allows the kdump crash recovery service -complete without being preempted by traditional power fencing methods. - -fence_kdump_send - -fence_kdump_send is a utility used to send messages that acknowledge that the -node itself has entered the kdump crash recovery service. The fence_kdump_send -utility is typically run in the kdump kernel after a cluster node has -encountered a kernel panic. Once the cluster node has entered the kdump crash -recovery service, fence_kdump_send will periodically send messages to all -cluster nodes. When the fence_kdump agent receives a valid message from the -failed nodes, fencing is complete. - -How to configure Pacemaker cluster environment: - -If we want to use kdump in Pacemaker cluster environment, fence-agents-kdump -should be installed in every nodes in the cluster. You can achieve this via -the following command: - - # yum install -y fence-agents-kdump - -Next is to add kdump_fence to the cluster. Assuming that the cluster consists -of three nodes, they are node1, node2 and node3, and use Pacemaker to perform -resource management and pcs as cli configuration tool. - -With pcs it is easy to add a stonith resource to the cluster. For example, add -a stonith resource named mykdumpfence with fence type of fence_kdump via the -following commands: - - # pcs stonith create mykdumpfence fence_kdump \ - pcmk_host_check=static-list pcmk_host_list="node1 node2 node3" - # pcs stonith update mykdumpfence pcmk_monitor_action=metadata --force - # pcs stonith update mykdumpfence pcmk_status_action=metadata --force - # pcs stonith update mykdumpfence pcmk_reboot_action=off --force - -Then enable stonith - # pcs property set stonith-enabled=true - -How to configure kdump: - -Actually there are two ways how to configure fence_kdump support: - -1) Pacemaker based clusters - If you have successfully configured fence_kdump in Pacemaker, there is - no need to add some special configuration in kdump. So please refer to - Kexec-Kdump-howto file for more information. - -2) Generic clusters - For other types of clusters there are two configuration options in - kdump.conf which enables fence_kdump support: - - fence_kdump_nodes - Contains list of cluster node(s) separated by space to send - fence_kdump notification to (this option is mandatory to enable - fence_kdump) - - fence_kdump_args - Command line arguments for fence_kdump_send (it can contain - all valid arguments except hosts to send notification to) - - These options will most probably be configured by your cluster software, - so please refer to your cluster documentation how to enable fence_kdump - support. - -Please be aware that these two ways cannot be combined and 2) has precedence -over 1). It means that if fence_kdump is configured using fence_kdump_nodes -and fence_kdump_args options in kdump.conf, Pacemaker configuration is not -used even if it exists. diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh deleted file mode 100755 index f7b58a2..0000000 --- a/kdump-lib-initramfs.sh +++ /dev/null @@ -1,173 +0,0 @@ -#!/bin/sh -# -# The code in this file will be used in initramfs environment, bash may -# not be the default shell. Any code added must be POSIX compliant. - -DEFAULT_PATH="/var/crash/" -DEFAULT_SSHKEY="/root/.ssh/kdump_id_rsa" -KDUMP_CONFIG_FILE="/etc/kdump.conf" -FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" -FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" -LVM_CONF="/etc/lvm/lvm.conf" - -# Read kdump config in well formated style -kdump_read_conf() -{ - # Following steps are applied in order: strip trailing comment, strip trailing space, - # strip heading space, match non-empty line, remove duplicated spaces between conf name and value - [ -f "$KDUMP_CONFIG_FILE" ] && sed -n -e "s/#.*//;s/\s*$//;s/^\s*//;s/\(\S\+\)\s*\(.*\)/\1 \2/p" $KDUMP_CONFIG_FILE -} - -# Retrieves config value defined in kdump.conf -# $1: config name, sed regexp compatible -kdump_get_conf_val() -{ - # For lines matching "^\s*$1\s+", remove matched part (config name including space), - # remove tailing comment, space, then store in hold space. Print out the hold buffer on last line. - [ -f "$KDUMP_CONFIG_FILE" ] && - sed -n -e "/^\s*\($1\)\s\+/{s/^\s*\($1\)\s\+//;s/#.*//;s/\s*$//;h};\${x;p}" $KDUMP_CONFIG_FILE -} - -is_mounted() -{ - [ -n "$1" ] && findmnt -k -n "$1" > /dev/null 2>&1 -} - -# $1: info type -# $2: mount source type -# $3: mount source -# $4: extra args -get_mount_info() -{ - __kdump_mnt=$(findmnt -k -n -r -o "$1" "--$2" "$3" $4) - - [ -z "$__kdump_mnt" ] && [ -e "/etc/fstab" ] && __kdump_mnt=$(findmnt -s -n -r -o "$1" "--$2" "$3" $4) - - echo "$__kdump_mnt" -} - -is_ipv6_address() -{ - echo "$1" | grep -q ":" -} - -is_fs_type_nfs() -{ - [ "$1" = "nfs" ] || [ "$1" = "nfs4" ] -} - -is_fs_type_virtiofs() -{ - [ "$1" = "virtiofs" ] -} - -# If $1 contains dracut_args "--mount", return -get_dracut_args_fstype() -{ - echo "$1" | sed -n "s/.*--mount .\(.*\)/\1/p" | cut -d' ' -f3 -} - -# If $1 contains dracut_args "--mount", return -get_dracut_args_target() -{ - echo "$1" | sed -n "s/.*--mount .\(.*\)/\1/p" | cut -d' ' -f1 -} - -get_save_path() -{ - __kdump_path=$(kdump_get_conf_val path) - [ -z "$__kdump_path" ] && __kdump_path=$DEFAULT_PATH - - # strip the duplicated "/" - echo "$__kdump_path" | tr -s / -} - -get_root_fs_device() -{ - findmnt -k -f -n -o SOURCE / -} - -# Return the current underlying device of a path, ignore bind mounts -get_target_from_path() -{ - __kdump_target=$(df "$1" 2> /dev/null | tail -1 | awk '{print $1}') - [ "$__kdump_target" = "/dev/root" ] && [ ! -e /dev/root ] && __kdump_target=$(get_root_fs_device) - echo "$__kdump_target" -} - -get_fs_type_from_target() -{ - get_mount_info FSTYPE source "$1" -f -} - -get_mntpoint_from_target() -{ - # --source is applied to ensure non-bind mount is returned - get_mount_info TARGET source "$1" -f -} - -is_ssh_dump_target() -{ - kdump_get_conf_val ssh | grep -q @ -} - -is_raw_dump_target() -{ - [ -n "$(kdump_get_conf_val raw)" ] -} - -is_virtiofs_dump_target() -{ - if [ -n "$(kdump_get_conf_val virtiofs)" ]; then - return 0 - fi - - if is_fs_type_virtiofs "$(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)")"; then - return 0 - fi - - if is_fs_type_virtiofs "$(get_fs_type_from_target "$(get_target_from_path "$(get_save_path)")")"; then - return 0 - fi - - return 1 -} - -is_nfs_dump_target() -{ - if [ -n "$(kdump_get_conf_val nfs)" ]; then - return 0 - fi - - if is_fs_type_nfs "$(get_dracut_args_fstype "$(kdump_get_conf_val dracut_args)")"; then - return 0 - fi - - if is_fs_type_nfs "$(get_fs_type_from_target "$(get_target_from_path "$(get_save_path)")")"; then - return 0 - fi - - return 1 -} - -is_lvm2_thinp_device() -{ - _device_path=$1 - _lvm2_thin_device=$(lvm lvs -S 'lv_layout=sparse && lv_layout=thin' \ - --nosuffix --noheadings -o vg_name,lv_name "$_device_path" 2> /dev/null) - - [ -n "$_lvm2_thin_device" ] -} - -kdump_get_ip_route() -{ - if ! _route=$(/sbin/ip -o route get to "$1" 2>&1); then - exit 1 - fi - echo "$_route" -} - -kdump_get_ip_route_field() -{ - echo "$1" | sed -n -e "s/^.*\<$2\>\s\+\(\S\+\).*$/\1/p" -} diff --git a/kdump-lib.sh b/kdump-lib.sh deleted file mode 100755 index 79714f9..0000000 --- a/kdump-lib.sh +++ /dev/null @@ -1,1117 +0,0 @@ -#!/bin/bash -# -# Kdump common variables and functions -# -if [[ ${__SOURCED__:+x} ]]; then - . ./kdump-lib-initramfs.sh -else - . /lib/kdump/kdump-lib-initramfs.sh -fi - -FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump/enabled" -FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump/registered" - -is_uki() -{ - local img - - img="$1" - - [[ -f "$img" ]] || return - [[ "$(file -b --mime-type "$img")" == application/x-dosexec ]] || return - objdump -h -j .linux "$img" &> /dev/null -} - -is_fadump_capable() -{ - # Check if firmware-assisted dump is enabled - # if no, fallback to kdump check - if [[ -f $FADUMP_ENABLED_SYS_NODE ]]; then - rc=$(< $FADUMP_ENABLED_SYS_NODE) - [[ $rc -eq 1 ]] && return 0 - fi - return 1 -} - -is_aws_aarch64() -{ - [[ "$(lscpu | grep "BIOS Model name")" =~ "AWS Graviton" ]] -} - -is_sme_or_sev_active() -{ - journalctl -q --dmesg --grep "^Memory Encryption Features active: AMD (SME|SEV)$" >/dev/null 2>&1 -} - -is_squash_available() -{ - local _version kmodule - - _version=$(_get_kdump_kernel_version) - for kmodule in squashfs overlay loop; do - modprobe -S "$_version" --dry-run $kmodule &> /dev/null || return 1 - done -} - -has_command() -{ - [[ -x $(command -v "$1") ]] -} - -dracut_have_option() -{ - local _option=$1 - ! dracut "$_option" 2>&1 | grep -q "unrecognized option" -} - -perror_exit() -{ - derror "$@" - exit 1 -} - -# Check if fence kdump is configured in Pacemaker cluster -is_pcs_fence_kdump() -{ - # no pcs or fence_kdump_send executables installed? - type -P pcs > /dev/null || return 1 - [[ -x $FENCE_KDUMP_SEND ]] || return 1 - - # fence kdump not configured? - (pcs cluster cib | grep 'type="fence_kdump"') &> /dev/null || return 1 -} - -# Check if fence_kdump is configured using kdump options -is_generic_fence_kdump() -{ - [[ -x $FENCE_KDUMP_SEND ]] || return 1 - - [[ $(kdump_get_conf_val fence_kdump_nodes) ]] -} - -to_dev_name() -{ - local dev="${1//\"/}" - - case "$dev" in - UUID=*) - blkid -U "${dev#UUID=}" - ;; - LABEL=*) - blkid -L "${dev#LABEL=}" - ;; - *) - echo "$dev" - ;; - esac -} - -is_user_configured_dump_target() -{ - [[ $(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|nfs\|ssh\|virtiofs") ]] || is_mount_in_dracut_args -} - -get_block_dump_target() -{ - local _target _fstype - - if is_ssh_dump_target || is_nfs_dump_target; then - return - fi - - _target=$(kdump_get_conf_val "ext[234]\|xfs\|btrfs\|minix\|raw\|virtiofs") - [[ -n $_target ]] && to_dev_name "$_target" && return - - _target=$(get_dracut_args_target "$(kdump_get_conf_val "dracut_args")") - [[ -b $_target ]] && to_dev_name "$_target" && return - - _fstype=$(get_dracut_args_fstype "$(kdump_get_conf_val "dracut_args")") - is_fs_type_virtiofs "$_fstype" && echo "$_target" && return - - _target=$(get_target_from_path "$(get_save_path)") - [[ -b $_target ]] && to_dev_name "$_target" && return - - _fstype=$(get_fs_type_from_target "$_target") - is_fs_type_virtiofs "$_fstype" && echo "$_target" && return -} - -is_dump_to_rootfs() -{ - [[ $(kdump_get_conf_val 'failure_action\|default') == dump_to_rootfs ]] -} - -is_lvm2_thinp_dump_target() -{ - _target=$(get_block_dump_target) - [ -n "$_target" ] && is_lvm2_thinp_device "$_target" -} - -get_failure_action_target() -{ - local _target - - if is_dump_to_rootfs; then - # Get rootfs device name - _target=$(get_root_fs_device) - [[ -b $_target ]] && to_dev_name "$_target" && return - is_fs_type_virtiofs "$(get_fs_type_from_target "$_target")" && echo "$_target" && return - # Then, must be nfs root - echo "nfs" - fi -} - -# Get kdump targets(including root in case of dump_to_rootfs). -get_kdump_targets() -{ - local _target _root - local kdump_targets - - _target=$(get_block_dump_target) - if [[ -n $_target ]]; then - kdump_targets=$_target - elif is_ssh_dump_target; then - kdump_targets="ssh" - else - kdump_targets="nfs" - fi - - # Add the root device if dump_to_rootfs is specified. - _root=$(get_failure_action_target) - if [[ -n $_root ]] && [[ $kdump_targets != "$_root" ]]; then - kdump_targets="$kdump_targets $_root" - fi - - echo "$kdump_targets" -} - -# Return the bind mount source path, return the path itself if it's not bind mounted -# Eg. if /path/to/src is bind mounted to /mnt/bind, then: -# /mnt/bind -> /path/to/src, /mnt/bind/dump -> /path/to/src/dump -# -# findmnt uses the option "-v, --nofsroot" to exclusive the [/dir] -# in the SOURCE column for bind-mounts, then if $_src equals to -# $_src_nofsroot, the mountpoint is not bind mounted directory. -# -# Below is just an example for mount info -# /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the -# directory is bind mounted. The former part represents the device path, rest -# part is the bind mounted directory which quotes by bracket "[]". -get_bind_mount_source() -{ - local _mnt _path _src _opt _fstype - local _fsroot _src_nofsroot - - _mnt=$(df "$1" | tail -1 | awk '{print $NF}') - _path=${1#"$_mnt"} - - _src=$(get_mount_info SOURCE target "$_mnt" -f) - _opt=$(get_mount_info OPTIONS target "$_mnt" -f) - _fstype=$(get_mount_info FSTYPE target "$_mnt" -f) - - # bind mount in fstab - if [[ -d $_src ]] && [[ $_fstype == none ]] && (echo "$_opt" | grep -q "\bbind\b"); then - echo "$_src$_path" && return - fi - - # direct mount - _src_nofsroot=$(get_mount_info SOURCE target "$_mnt" -v -f) - if [[ $_src_nofsroot == "$_src" ]]; then - echo "$_mnt$_path" && return - fi - - _fsroot=${_src#"${_src_nofsroot}"[} - _fsroot=${_fsroot%]} - _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) - - # for btrfs, _fsroot will also contain the subvol value as well, strip it - if [[ $_fstype == btrfs ]]; then - local _subvol - _subvol=${_opt#*subvol=} - _subvol=${_subvol%,*} - _fsroot=${_fsroot#"$_subvol"} - fi - echo "$_mnt$_fsroot$_path" -} - -get_mntopt_from_target() -{ - get_mount_info OPTIONS source "$1" -f -} - -# Get the path where the target will be mounted in kdump kernel -# $1: kdump target device -get_kdump_mntpoint_from_target() -{ - local _mntpoint - - _mntpoint=$(get_mntpoint_from_target "$1") - # mount under /sysroot if dump to root disk or mount under - # mount under /kdumproot if dump target is not mounted in first kernel - # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel. - # systemd will be in charge to umount it. - if [[ -z $_mntpoint ]]; then - _mntpoint="/kdumproot" - else - if [[ $_mntpoint == "/" ]]; then - _mntpoint="/sysroot" - else - _mntpoint="/kdumproot/$_mntpoint" - fi - fi - - # strip duplicated "/" - echo $_mntpoint | tr -s "/" -} - -kdump_get_persistent_dev() -{ - local dev="${1//\"/}" - - case "$dev" in - UUID=*) - dev=$(blkid -U "${dev#UUID=}") - ;; - LABEL=*) - dev=$(blkid -L "${dev#LABEL=}") - ;; - esac - get_persistent_dev "$dev" -} - -is_ostree() -{ - test -f /run/ostree-booted -} - -# get ip address or hostname from nfs/ssh config value -get_remote_host() -{ - local _config_val=$1 - - # ipv6 address in kdump.conf is around with "[]", - # factor out the ipv6 address - _config_val=${_config_val#*@} - _config_val=${_config_val%:/*} - _config_val=${_config_val#[} - _config_val=${_config_val%]} - echo "$_config_val" -} - -is_hostname() -{ - local _hostname - - _hostname=$(echo "$1" | grep ":") - if [[ -n $_hostname ]]; then - return 1 - fi - echo "$1" | grep -q "[a-zA-Z]" -} - -# Get value by a field using "nmcli -g" -# Usage: get_nmcli_value_by_field -# -# "nmcli --get-values" allows us to retrive value(s) by field, for example, -# nmcli --get-values connection show /org/freedesktop/NetworkManager/ActiveConnection/1 -# returns the following value for the corresponding field respectively, -# Field Value -# IP4.DNS "10.19.42.41 | 10.11.5.19 | 10.5.30.160" -# 802-3-ethernet.s390-subchannels "" -# bond.options "mode=balance-rr" -get_nmcli_value_by_field() -{ - LANG=C nmcli --get-values "$@" -} - -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 -} - -have_compression_in_dracut_args() -{ - [[ "$(kdump_get_conf_val dracut_args)" =~ (^|[[:space:]])--(gzip|bzip2|lzma|xz|lzo|lz4|zstd|no-compress|compress|squash-compressor)([[:space:]]|$) ]] -} - -# If "dracut_args" contains "--mount" information, use it -# directly without any check(users are expected to ensure -# its correctness). -is_mount_in_dracut_args() -{ - [[ " $(kdump_get_conf_val dracut_args)" =~ .*[[:space:]]--mount[=[:space:]].* ]] -} - -get_reserved_mem_size() -{ - local reserved_mem_size=0 - - if is_fadump_capable; then - reserved_mem_size=$(< /sys/kernel/fadump/mem_reserved) - else - reserved_mem_size=$(< /sys/kernel/kexec_crash_size) - fi - - echo "$reserved_mem_size" -} - -check_crash_mem_reserved() -{ - local mem_reserved - - mem_reserved=$(get_reserved_mem_size) - if [[ $mem_reserved -eq 0 ]]; then - derror "No memory reserved for crash kernel" - return 1 - fi - - return 0 -} - -check_kdump_feasibility() -{ - if [[ ! -e /sys/kernel/kexec_crash_loaded ]]; then - derror "Kdump is not supported on this kernel" - return 1 - fi - check_crash_mem_reserved - return $? -} - -is_kernel_loaded() -{ - local _sysfs _mode - - _mode=$1 - - case "$_mode" in - kdump) - _sysfs="/sys/kernel/kexec_crash_loaded" - ;; - fadump) - _sysfs="$FADUMP_REGISTER_SYS_NODE" - ;; - *) - derror "Unknown dump mode '$_mode' provided" - return 1 - ;; - esac - - if [[ ! -f $_sysfs ]]; then - derror "$_mode is not supported on this kernel" - return 1 - fi - - [[ $(< $_sysfs) -eq 1 ]] -} - -# -# This function returns the "apicid" of the boot -# cpu (cpu 0) if present. -# -get_bootcpu_apicid() -{ - awk ' \ - BEGIN { CPU = "-1"; } \ - $1=="processor" && $2==":" { CPU = $NF; } \ - CPU=="0" && /^apicid/ { print $NF; } \ - ' \ - /proc/cpuinfo -} - -# This function check iomem and determines if we have more than -# 4GB of ram available. Returns 1 if we do, 0 if we dont -need_64bit_headers() -{ - return "$(tail -n 1 /proc/iomem | awk '{ split ($1, r, "-"); - print (strtonum("0x" r[2]) > strtonum("0xffffffff")); }')" -} - -# Check if secure boot is being enforced. -# -# Per Peter Jones, we need check efivar SecureBoot-$(the UUID) and -# SetupMode-$(the UUID), they are both 5 bytes binary data. The first four -# bytes are the attributes associated with the variable and can safely be -# ignored, the last bytes are one-byte true-or-false variables. If SecureBoot -# is 1 and SetupMode is 0, then secure boot is being enforced. -# -# Assume efivars is mounted at /sys/firmware/efi/efivars. -is_secure_boot_enforced() -{ - local secure_boot_file setup_mode_file - local secure_boot_byte setup_mode_byte - - # On powerpc, secure boot is enforced if: - # host secure boot: /ibm,secure-boot/os-secureboot-enforcing DT property exists - # guest secure boot: /ibm,secure-boot >= 2 - if [[ -f /proc/device-tree/ibm,secureboot/os-secureboot-enforcing ]]; then - return 0 - fi - if [[ -f /proc/device-tree/ibm,secure-boot ]] && - [[ $(lsprop /proc/device-tree/ibm,secure-boot | tail -1) -ge 2 ]]; then - return 0 - fi - - # Detect secure boot on x86 and arm64 - secure_boot_file=$(find /sys/firmware/efi/efivars -name "SecureBoot-*" 2> /dev/null) - setup_mode_file=$(find /sys/firmware/efi/efivars -name "SetupMode-*" 2> /dev/null) - - if [[ -f $secure_boot_file ]] && [[ -f $setup_mode_file ]]; then - secure_boot_byte=$(hexdump -v -e '/1 "%d\ "' "$secure_boot_file" | cut -d' ' -f 5) - setup_mode_byte=$(hexdump -v -e '/1 "%d\ "' "$setup_mode_file" | cut -d' ' -f 5) - - if [[ $secure_boot_byte == "1" ]] && [[ $setup_mode_byte == "0" ]]; then - return 0 - fi - fi - - # Detect secure boot on s390x - if [[ -e "/sys/firmware/ipl/secure" && "$(< /sys/firmware/ipl/secure)" == "1" ]]; then - return 0 - fi - - return 1 -} - -# -# prepare_kexec_args -# This function prepares kexec argument. -# -prepare_kexec_args() -{ - local kexec_args=$1 - local found_elf_args - - ARCH=$(uname -m) - if [[ $ARCH == "i686" ]] || [[ $ARCH == "i386" ]]; then - need_64bit_headers - if [[ $? == 1 ]]; then - found_elf_args=$(echo "$kexec_args" | grep elf32-core-headers) - if [[ -n $found_elf_args ]]; then - dwarn "Warning: elf32-core-headers overrides correct elf64 setting" - else - kexec_args="$kexec_args --elf64-core-headers" - fi - else - found_elf_args=$(echo "$kexec_args" | grep elf64-core-headers) - if [[ -z $found_elf_args ]]; then - kexec_args="$kexec_args --elf32-core-headers" - fi - fi - fi - - # For secureboot enabled machines, use new kexec file based syscall. - # Old syscall will always fail as it does not have capability to do - # kernel signature verification. - if is_secure_boot_enforced; then - dinfo "Secure Boot is enabled. Using kexec file based syscall." - kexec_args="$kexec_args -s" - fi - - echo "$kexec_args" -} - -# prepare_kdump_kernel -# This function return kdump_kernel given a kernel version. -prepare_kdump_kernel() -{ - local kdump_kernelver=$1 - local dir img boot_dirlist boot_imglist kdump_kernel machine_id - read -r machine_id < /etc/machine-id - - boot_dirlist=${KDUMP_BOOTDIR:-"/boot /boot/efi /efi /"} - boot_imglist="$KDUMP_IMG-$kdump_kernelver$KDUMP_IMG_EXT \ - $machine_id/$kdump_kernelver/$KDUMP_IMG \ - EFI/Linux/$machine_id-$kdump_kernelver.efi" - - # The kernel of OSTree based systems is not in the standard locations. - if is_ostree; then - boot_dirlist="$(echo /boot/ostree/*) $boot_dirlist" - fi - - # Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format - boot_img="$(grep -P -o '^BOOT_IMAGE=(\S+)' /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\)/\2/")" - if [[ "$boot_img" == *"$kdump_kernelver" ]]; then - boot_imglist="$boot_img $boot_imglist" - fi - - for dir in $boot_dirlist; do - for img in $boot_imglist; do - if [[ -f "$dir/$img" ]]; then - kdump_kernel=$(echo "$dir/$img" | tr -s '/') - break 2 - fi - done - done - echo "$kdump_kernel" -} - -_is_valid_kver() -{ - [[ -f /usr/lib/modules/$1/modules.dep ]] -} - -# This function is introduced since 64k variant may be installed on 4k or vice versa -# $1 the kernel path name. -parse_kver_from_path() -{ - local _img _kver - - [[ -z "$1" ]] && return - - _img=$1 - BLS_ENTRY_TOKEN=$( - _kver=${_img##*/vmlinuz-} - _kver=${_kver%"$KDUMP_IMG_EXT"} - if _is_valid_kver "$_kver"; then - echo "$_kver" - return - fi - - # BLS recommended image names, i.e. $BOOT///linux - _kver=${_img##*/"$BLS_ENTRY_TOKEN"/} - _kver=${_kver%%/*} - if _is_valid_kver "$_kver"; then - echo "$_kver" - return - fi - - # Fedora UKI installation, i.e. $BOOT/efi/EFI/Linux/-.efi - _kver=${_img##*/"$BLS_ENTRY_TOKEN"-} - _kver=${_kver%.efi} - if _is_valid_kver "$_kver"; then - echo "$_kver" - return - fi - - ddebug "Could not parse version from $_img" -} - -_get_kdump_kernel_version() -{ - local _version _version_nondebug - - if [[ -n "$KDUMP_KERNELVER" ]]; then - echo "$KDUMP_KERNELVER" - return - fi - - _version=$(uname -r) - if [[ ! "$_version" =~ [+|-]debug$ ]]; then - echo "$_version" - return - fi - - _version_nondebug=${_version%+debug} - _version_nondebug=${_version_nondebug%-debug} - if _is_valid_kver "$_version_nondebug"; then - dinfo "Use of debug kernel detected. Trying to use $_version_nondebug" - echo "$_version_nondebug" - else - dinfo "Use of debug kernel detected but cannot find $_version_nondebug. Falling back to $_version" - echo "$_version" - fi -} - -# -# Detect initrd and kernel location, results are stored in global environmental variables: -# KDUMP_BOOTDIR, KDUMP_KERNELVER, KDUMP_KERNEL, DEFAULT_INITRD, and KDUMP_INITRD -# -# Expectes KDUMP_BOOTDIR, KDUMP_IMG, KDUMP_IMG_EXT, KDUMP_KERNELVER to be loaded from config already -# and will prefer already set values so user can specify custom kernel/initramfs location -# -prepare_kdump_bootinfo() -{ - local boot_initrdlist default_initrd_base var_target_initrd_dir - - KDUMP_KERNELVER=$(_get_kdump_kernel_version) - KDUMP_KERNEL=$(prepare_kdump_kernel "$KDUMP_KERNELVER") - - if ! [[ -e $KDUMP_KERNEL ]]; then - derror "Failed to detect kdump kernel location" - return 1 - fi - - # For 64k variant, e.g. vmlinuz-5.14.0-327.el9.aarch64+64k-debug - if [[ "$KDUMP_KERNEL" == *"+debug" || "$KDUMP_KERNEL" == *"64k-debug" ]]; then - dwarn "Using debug kernel, you may need to set a larger crashkernel than the default value." - fi - - # Set KDUMP_BOOTDIR to where kernel image is stored - if is_uki "$KDUMP_KERNEL"; then - KDUMP_BOOTDIR=/boot - else - KDUMP_BOOTDIR=$(dirname "$KDUMP_KERNEL") - fi - - # Default initrd should just stay aside of kernel image, try to find it in KDUMP_BOOTDIR - boot_initrdlist="initramfs-$KDUMP_KERNELVER.img initrd" - for initrd in $boot_initrdlist; do - if [[ -f "$KDUMP_BOOTDIR/$initrd" ]]; then - default_initrd_base="$initrd" - DEFAULT_INITRD="$KDUMP_BOOTDIR/$default_initrd_base" - break - fi - done - - # Create kdump initrd basename from default initrd basename - # initramfs-5.7.9-200.fc32.x86_64.img => initramfs-5.7.9-200.fc32.x86_64kdump.img - # initrd => initrdkdump - if [[ -z $default_initrd_base ]]; then - kdump_initrd_base=initramfs-${KDUMP_KERNELVER}kdump.img - elif [[ $default_initrd_base == *.* ]]; then - kdump_initrd_base=${default_initrd_base%.*}kdump.${DEFAULT_INITRD##*.} - else - kdump_initrd_base=${default_initrd_base}kdump - fi - - # Place kdump initrd in $(/var/lib/kdump) if $(KDUMP_BOOTDIR) not writable - if [[ ! -w $KDUMP_BOOTDIR ]]; then - var_target_initrd_dir="/var/lib/kdump" - mkdir -p "$var_target_initrd_dir" - KDUMP_INITRD="$var_target_initrd_dir/$kdump_initrd_base" - else - KDUMP_INITRD="$KDUMP_BOOTDIR/$kdump_initrd_base" - fi -} - -get_watchdog_drvs() -{ - local _wdtdrvs _drv _dir - - for _dir in /sys/class/watchdog/*; do - # device/modalias will return driver of this device - [[ -f "$_dir/device/modalias" ]] || continue - _drv=$(< "$_dir/device/modalias") - _drv=$(modprobe --set-version "$KDUMP_KERNELVER" -R "$_drv" 2> /dev/null) - for i in $_drv; do - if ! [[ " $_wdtdrvs " == *" $i "* ]]; then - _wdtdrvs="$_wdtdrvs $i" - fi - done - done - - echo "$_wdtdrvs" -} - -_cmdline_parse() -{ - local opt val - - while read -r opt; do - if [[ $opt =~ = ]]; then - val=${opt#*=} - opt=${opt%%=*} - # ignore options like 'foo=' - [[ -z $val ]] && continue - # xargs removes quotes, add them again - [[ $val =~ [[:space:]] ]] && val="\"$val\"" - else - val="" - fi - - echo "$opt $val" - done <<< "$(echo "$1" | xargs -n 1 echo)" -} - -# -# prepare_cmdline -# This function performs a series of edits on the command line. -# Store the final result in global $KDUMP_COMMANDLINE. -prepare_cmdline() -{ - local in out append opt val id drv - local -A remove - - in=${1:-$(< /proc/cmdline)} - while read -r opt val; do - [[ -n "$opt" ]] || continue - remove[$opt]=1 - done <<< "$(_cmdline_parse "$2")" - append=$3 - - - # These params should always be removed - remove[crashkernel]=1 - remove[panic_on_warn]=1 - - # Always remove "root=X", as we now explicitly generate all kinds - # of dump target mount information including root fs. - # - # We do this before KDUMP_COMMANDLINE_APPEND, if one really cares - # about it(e.g. for debug purpose), then can pass "root=X" using - # KDUMP_COMMANDLINE_APPEND. - remove[root]=1 - - # With the help of "--hostonly-cmdline", we can avoid some interitage. - remove[rd.lvm.lv]=1 - remove[rd.luks.uuid]=1 - remove[rd.dm.uuid]=1 - remove[rd.md.uuid]=1 - remove[fcoe]=1 - - # Remove netroot, rd.iscsi.initiator and iscsi_initiator since - # we get duplicate entries for the same in case iscsi code adds - # it as well. - remove[netroot]=1 - remove[rd.iscsi.initiator]=1 - remove[iscsi_initiator]=1 - - while read -r opt val; do - [[ -n "$opt" ]] || continue - [[ -n "${remove[$opt]}" ]] && continue - - if [[ -n "$val" ]]; then - out+="$opt=$val " - else - out+="$opt " - fi - done <<< "$(_cmdline_parse "$in")" - - out+="$append " - - id=$(get_bootcpu_apicid) - if [[ -n "${id}" ]]; then - out+="disable_cpu_apicid=$id " - fi - - # If any watchdog is used, set it's pretimeout to 0. pretimeout let - # watchdog panic the kernel first, and reset the system after the - # panic. If the system is already in kdump, panic is not helpful - # and only increase the chance of watchdog failure. - for drv in $(get_watchdog_drvs); do - out+="$drv.pretimeout=0 " - - if [[ $drv == hpwdt ]]; then - # hpwdt have a special parameter kdumptimeout, it is - # only supposed to be set to non-zero in first kernel. - # In kdump, non-zero value could prevent the watchdog - # from resetting the system. - out+="$drv.kdumptimeout=0 " - fi - done - - # This is a workaround on AWS platform. Always remove irqpoll since it - # may cause the hot-remove of some pci hotplug device. - is_aws_aarch64 && out=$(echo "$out" | sed -e "/\//") - - # Always disable gpt-auto-generator as it hangs during boot of the - # crash kernel. Furthermore we know which disk will be used for dumping - # (if at all) and add it explicitly. - is_uki "$KDUMP_KERNEL" && out+="rd.systemd.gpt_auto=no " - - # Trim unnecessary whitespaces - echo "$out" | sed -e "s/^ *//g" -e "s/ *$//g" -e "s/ \+/ /g" -} - -PROC_IOMEM=/proc/iomem -#get system memory size i.e. memblock.memory.total_size in the unit of GB -get_system_size() -{ - sum=$(sed -n "s/\s*\([0-9a-fA-F]\+\)-\([0-9a-fA-F]\+\) : System RAM$/+ 0x\2 - 0x\1 + 1/p" $PROC_IOMEM) - echo $(( (sum) / 1024 / 1024 / 1024)) -} - -# Return the recommended size for the reserved crashkernel memory -# depending on the system memory size. -# -# This functions is expected to be consistent with the parse_crashkernel_mem() -# in kernel i.e. how kernel allocates the kdump memory given the crashkernel -# parameter crashkernel=range1:size1[,range2:size2,…] and the system memory -# size. -get_recommend_size() -{ - local mem_size=$1 - local _ck_cmdline=$2 - local range start start_unit end end_unit size - - while read -r -d , range; do - # need to use non-default IFS as double spaces are used as a - # single delimiter while commas aren't... - IFS=, read -r start start_unit end end_unit size <<< \ - "$(echo "$range" | sed -n "s/\([0-9]\+\)\([GT]\?\)-\([0-9]*\)\([GT]\?\):\([0-9]\+[MG]\)/\1,\2,\3,\4,\5/p")" - - # aka. 102400T - end=${end:-104857600} - [[ "$end_unit" == T ]] && end=$((end * 1024)) - [[ "$start_unit" == T ]] && start=$((start * 1024)) - - if [[ $mem_size -ge $start ]] && [[ $mem_size -lt $end ]]; then - echo "$size" - return - fi - - # append a ',' as read expects the 'file' to end with a delimiter - done <<< "$_ck_cmdline," - - # no matching range found - echo "0M" -} - -has_mlx5() -{ - [[ -d /sys/bus/pci/drivers/mlx5_core ]] -} - -has_aarch64_smmu() -{ - ls /sys/devices/platform/arm-smmu-* 1> /dev/null 2>&1 -} - -is_memsize() { [[ "$1" =~ ^[+-]?[0-9]+[KkMmGgTtPbEe]?$ ]]; } - -# range defined for crashkernel parameter -# i.e. -[] -is_memrange() -{ - is_memsize "${1%-*}" || return 1 - [[ -n ${1#*-} ]] || return 0 - is_memsize "${1#*-}" -} - -to_bytes() -{ - local _s - - _s="$1" - is_memsize "$_s" || return 1 - - case "${_s: -1}" in - K|k) - _s=${_s::-1} - _s="$((_s * 1024))" - ;; - M|m) - _s=${_s::-1} - _s="$((_s * 1024 * 1024))" - ;; - G|g) - _s=${_s::-1} - _s="$((_s * 1024 * 1024 * 1024))" - ;; - T|t) - _s=${_s::-1} - _s="$((_s * 1024 * 1024 * 1024 * 1024))" - ;; - P|p) - _s=${_s::-1} - _s="$((_s * 1024 * 1024 * 1024 * 1024 * 1024))" - ;; - E|e) - _s=${_s::-1} - _s="$((_s * 1024 * 1024 * 1024 * 1024 * 1024 * 1024))" - ;; - *) - ;; - esac - echo "$_s" -} - -memsize_add() -{ - local -a units=("" "K" "M" "G" "T" "P" "E") - local i a b - - a=$(to_bytes "$1") || return 1 - b=$(to_bytes "$2") || return 1 - i=0 - - (( a += b )) - while :; do - [[ $(( a / 1024 )) -eq 0 ]] && break - [[ $(( a % 1024 )) -ne 0 ]] && break - [[ $(( ${#units[@]} - 1 )) -eq $i ]] && break - - (( a /= 1024 )) - (( i += 1 )) - done - - echo "${a}${units[$i]}" -} - -_crashkernel_parse() -{ - local ck entry - local range size offset - - ck="$1" - - if [[ "$ck" == *@* ]]; then - offset="@${ck##*@}" - ck=${ck%@*} - elif [[ "$ck" == *,high ]] || [[ "$ck" == *,low ]]; then - offset=",${ck##*,}" - ck=${ck%,*} - else - offset='' - fi - - while read -d , -r entry; do - [[ -n "$entry" ]] || continue - if [[ "$entry" == *:* ]]; then - range=${entry%:*} - size=${entry#*:} - else - range="" - size=${entry} - fi - - echo "$size;$range;" - done <<< "$ck," - echo ";;$offset" -} - -# $1 crashkernel command line parameter -# $2 size to be added -_crashkernel_add() -{ - local ck delta ret - local range size offset - - ck="$1" - delta="$2" - ret="" - - while IFS=';' read -r size range offset; do - if [[ -n "$offset" ]]; then - ret="${ret%,}$offset" - break - fi - - [[ -n "$size" ]] || continue - if [[ -n "$range" ]]; then - is_memrange "$range" || return 1 - ret+="$range:" - fi - - size=$(memsize_add "$size" "$delta") || return 1 - ret+="$size," - done < <( _crashkernel_parse "$ck") - - echo "${ret%,}" -} - -# get default crashkernel -# $1 dump mode, if not specified, dump_mode will be judged by is_fadump_capable -# $2 kernel-release, if not specified, got by _get_kdump_kernel_version -kdump_get_arch_recommend_crashkernel() -{ - local _arch _ck_cmdline _dump_mode - local _delta=0 - - if [[ -z "$1" ]]; then - if is_fadump_capable; then - _dump_mode=fadump - else - _dump_mode=kdump - fi - else - _dump_mode=$1 - fi - - _arch=$(uname -m) - - if [[ $_arch == "x86_64" ]] || [[ $_arch == "s390x" ]]; then - _ck_cmdline="1G-4G:192M,4G-64G:256M,64G-:512M" - is_sme_or_sev_active && ((_delta += 64)) - elif [[ $_arch == "aarch64" ]]; then - local _running_kernel - - # Base line for 4K variant kernel. The formula is based on x86 plus extra = 64M - _ck_cmdline="1G-4G:256M,4G-64G:320M,64G-:576M" - if [[ -z "$2" ]]; then - _running_kernel=$(_get_kdump_kernel_version) - else - _running_kernel=$2 - fi - - # the naming convention of 64k variant suffixes with +64k, e.g. "vmlinuz-5.14.0-312.el9.aarch64+64k" - if echo "$_running_kernel" | grep -q 64k; then - # Without smmu, the diff of MemFree between 4K and 64K measured on a high end aarch64 machine is 82M. - # Picking up 100M to cover this diff. And finally, we have "1G-4G:356M;4G-64G:420M;64G-:676M" - ((_delta += 100)) - # On a 64K system, the extra 384MB is calculated by: cmdq_num * 16 bytes + evtq_num * 32B + priq_num * 16B - # While on a 4K system, it is negligible - has_aarch64_smmu && ((_delta += 384)) - #64k kernel, mlx5 consumes extra 188M memory, and choose 200M - has_mlx5 && ((_delta += 200)) - else - #4k kernel, mlx5 consumes extra 124M memory, and choose 150M - has_mlx5 && ((_delta += 150)) - fi - elif [[ $_arch == "ppc64le" ]]; then - if [[ $_dump_mode == "fadump" ]]; then - _ck_cmdline="4G-16G:768M,16G-64G:1G,64G-128G:2G,128G-1T:4G,1T-2T:6G,2T-4T:12G,4T-8T:20G,8T-16T:36G,16T-32T:64G,32T-64T:128G,64T-:180G" - else - _ck_cmdline="2G-4G:384M,4G-16G:512M,16G-64G:1G,64G-128G:2G,128G-:4G" - fi - fi - - echo -n "$(_crashkernel_add "$_ck_cmdline" "${_delta}M")" -} - -# return recommended size based on current system RAM size -# $1: kernel version, if not set, will defaults to $(uname -r) -kdump_get_arch_recommend_size() -{ - local _ck_cmdline _sys_mem - - if ! [[ -r "/proc/iomem" ]]; then - echo "Error, can not access /proc/iomem." - return 1 - fi - _sys_mem=$(get_system_size) - _ck_cmdline=$(kdump_get_arch_recommend_crashkernel) - _ck_cmdline=${_ck_cmdline//-:/-102400T:} - get_recommend_size "$_sys_mem" "$_ck_cmdline" -} - -# Print all underlying crypt devices of a block device -# print nothing if device is not on top of a crypt device -# $1: the block device to be checked in maj:min format -get_luks_crypt_dev() -{ - local _type - - [[ -b /dev/block/$1 ]] || return 1 - - _type=$(blkid -u filesystem,crypto -o export -- "/dev/block/$1" | \ - sed -n -E "s/^TYPE=(.*)$/\1/p") - [[ $_type == "crypto_LUKS" ]] && echo "$1" - - for _x in "/sys/dev/block/$1/slaves/"*; do - [[ -f $_x/dev ]] || continue - [[ $_x/subsystem -ef /sys/class/block ]] || continue - get_luks_crypt_dev "$(< "$_x/dev")" - done -} - -# kdump_get_maj_min -# Prints the major and minor of a device node. -# Example: -# $ get_maj_min /dev/sda2 -# 8:2 -kdump_get_maj_min() -{ - local _majmin - _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)" - printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" -} - -get_all_kdump_crypt_dev() -{ - local _dev - - for _dev in $(get_block_dump_target); do - get_luks_crypt_dev "$(kdump_get_maj_min "$_dev")" - done -} diff --git a/kdump-logger.sh b/kdump-logger.sh deleted file mode 100755 index 3fd433d..0000000 --- a/kdump-logger.sh +++ /dev/null @@ -1,355 +0,0 @@ -#!/bin/sh -# -# This comes from the dracut-logger.sh -# -# 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 (3) -# The INFO level designates informational messages that highlight the -# progress of the application at coarse-grained level. -# - dwarn (2) -# The WARN level designates potentially harmful situations. -# - derror (1) -# The ERROR level designates error events that might still allow the -# application to continue running. -# -# 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, 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! -# -# The code in this file might be run in an environment without bash. -# Any code added must be POSIX compliant. - -# 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() -{ - [ -f /lib/dracut-lib.sh ] && kdump_sysloglvl=$(getarg rd.kdumploglvl) - [ -z "$kdump_sysloglvl" ] && return 1; - - if [ -f /lib/dracut-lib.sh ] && ! isdigit "$kdump_sysloglvl"; then - return 1 - fi - - 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() { - ret=0 - - if [ -s /proc/vmcore ];then - if ! get_kdump_loglvl; 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 - if ! check_loglvl "$loglvl"; 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 - - if [ "$UID" -ne 0 ]; then - kdump_kmsgloglvl=0 - kdump_sysloglvl=0 - fi - - if [ "$kdump_sysloglvl" -gt 0 ]; then - if [ -d /run/systemd/journal ] \ - && systemd-cat --version 1>/dev/null 2>&1 \ - && systemctl --quiet is-active systemd-journald.socket 1>/dev/null 2>&1; then - readonly _systemdcatfile="/var/tmp/systemd-cat" - mkfifo "$_systemdcatfile" 1>/dev/null 2>&1 - readonly _dlogfd=15 - systemd-cat -t 'kdump' --level-prefix=true <"$_systemdcatfile" & - exec 15>"$_systemdcatfile" - elif ! [ -S /dev/log ] && [ -w /dev/log ] || ! command -v logger >/dev/null; then - # We cannot log to syslog, so turn this facility off. - kdump_kmsgloglvl=$kdump_sysloglvl - kdump_sysloglvl=0 - ret=1 - errmsg="No '/dev/log' or 'logger' included for syslog logging" - fi - fi - - kdump_maxloglvl=0 - for _dlog_lvl in $kdump_stdloglvl $kdump_sysloglvl $kdump_kmsgloglvl; do - [ $_dlog_lvl -gt $kdump_maxloglvl ] && kdump_maxloglvl=$_dlog_lvl - done - readonly kdump_maxloglvl - export kdump_maxloglvl - - if [ $kdump_stdloglvl -lt 4 ] && [ $kdump_kmsgloglvl -lt 4 ] && [ $kdump_sysloglvl -lt 4 ]; then - unset ddebug - ddebug() { :; }; - fi - - if [ $kdump_stdloglvl -lt 3 ] && [ $kdump_kmsgloglvl -lt 3 ] && [ $kdump_sysloglvl -lt 3 ]; then - unset dinfo - dinfo() { :; }; - fi - - 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 1 ] && [ $kdump_kmsgloglvl -lt 1 ] && [ $kdump_sysloglvl -lt 1 ]; then - unset derror - derror() { :; }; - fi - - [ -n "$errmsg" ] && derror "$errmsg" - - return $ret -} - -## @brief Converts numeric level to logger priority defined by POSIX.2. -# -# @param $1: 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 error;; - 2) echo warning;; - 3) echo info;; - 4) echo debug;; - *) return 1;; - esac -} - -## @brief Converts logger numeric level to syslog log level -# -# @param $1: 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 -# -# Conversion is done as follows: -# -# -# none -> LOG_EMERG (0) -# none -> LOG_ALERT (1) -# none -> LOG_CRIT (2) -# ERROR(1) -> LOG_ERR (3) -# WARN(2) -> LOG_WARNING (4) -# none -> LOG_NOTICE (5) -# INFO(3) -> LOG_INFO (6) -# DEBUG(4) -> LOG_DEBUG (7) -# -# -# @see /usr/include/sys/syslog.h -_dlvl2syslvl() { - case "$1" in - 1) set -- 3;; - 2) set -- 4;; - 3) set -- 6;; - 4) set -- 7;; - *) return 1;; - esac - - # 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 + $1)) -} - -## @brief Prints to stderr, to syslog and/or /dev/kmsg given message with -# given level (priority). -# -# @param $1: Numeric logging level. -# @param $2: Message. -# @retval 0 It's always returned, even if logging failed. -# -# @note This function is not supposed to be called manually. Please use -# dinfo(), ddebug(), or others instead which wrap this one. -# -# 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: -# -# X: some message -# -# where @c X is the first letter of logging level. See module description for -# details on that. -# -# Message to syslog is sent with tag @c kdump. Priorities are mapped as -# following: -# - @c ERROR to @c error -# - @c WARN to @c warning -# - @c INFO to @c info -# - @c DEBUG to @c debug -_do_dlog() { - [ "$1" -le $kdump_stdloglvl ] && printf -- 'kdump: %s\n' "$2" >&2 - - if [ "$1" -le $kdump_sysloglvl ]; then - if [ "$_dlogfd" ]; then - printf -- "<%s>%s\n" "$(($(_dlvl2syslvl "$1") & 7))" "$2" 1>&$_dlogfd - else - logger -t "kdump[$$]" -p "$(_lvl2syspri "$1")" -- "$2" - fi - fi - - [ "$1" -le $kdump_kmsgloglvl ] && \ - echo "<$(_dlvl2syslvl "$1")>kdump[$$] $2" >/dev/kmsg -} - -## @brief Internal helper function for _do_dlog() -# -# @param $1: Numeric logging level. -# @param $2 [...]: Message. -# @retval 0 It's always returned, even if logging failed. -# -# @note This function is not supposed to be called manually. Please use -# 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 -# a message. -# -# This enables: -# dwarn "This is a warning" -# echo "This is a warning" | dwarn -dlog() { - [ -z "$kdump_maxloglvl" ] && return 0 - [ "$1" -le "$kdump_maxloglvl" ] || return 0 - - if [ $# -gt 1 ]; then - _dlog_lvl=$1; shift - _do_dlog "$_dlog_lvl" "$*" - else - while read -r line || [ -n "$line" ]; do - _do_dlog "$1" "$line" - done - fi -} - -## @brief Logs message at DEBUG level (4) -# -# @param msg Message. -# @retval 0 It's always returned, even if logging failed. -ddebug() { - set +x - dlog 4 "$@" - if [ -n "$debug" ]; then - set -x - fi -} - -## @brief Logs message at INFO level (3) -# -# @param msg Message. -# @retval 0 It's always returned, even if logging failed. -dinfo() { - set +x - dlog 3 "$@" - if [ -n "$debug" ]; then - set -x - fi -} - -## @brief Logs message at WARN level (2) -# -# @param msg Message. -# @retval 0 It's always returned, even if logging failed. -dwarn() { - set +x - dlog 2 "$@" - if [ -n "$debug" ]; then - set -x - fi -} - -## @brief It's an alias to dwarn() function. -# -# @param msg Message. -# @retval 0 It's always returned, even if logging failed. -dwarning() { - set +x - dwarn "$@" - if [ -n "$debug" ]; then - set -x - fi -} - -## @brief Logs message at ERROR level (1) -# -# @param msg Message. -# @retval 0 It's always returned, even if logging failed. -derror() { - set +x - dlog 1 "$@" - if [ -n "$debug" ]; then - set -x - fi -} diff --git a/kdump-migrate-action.sh b/kdump-migrate-action.sh deleted file mode 100755 index c516639..0000000 --- a/kdump-migrate-action.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -systemctl is-active kdump -if [ $? -ne 0 ]; then - exit 0 -fi - -/usr/lib/kdump/kdump-restart.sh diff --git a/kdump-restart.sh b/kdump-restart.sh deleted file mode 100644 index a9ecfc1..0000000 --- a/kdump-restart.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -export PATH="$PATH:/usr/bin:/usr/sbin" - -exec >>/var/log/kdump-migration.log 2>&1 - -echo "kdump: Partition Migration detected. Rebuilding initramfs image to reload." -/usr/bin/kdumpctl rebuild -/usr/bin/kdumpctl reload diff --git a/kdump-udev-throttler b/kdump-udev-throttler deleted file mode 100755 index cd77a31..0000000 --- a/kdump-udev-throttler +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# This util helps to reduce the workload of kdump service restarting -# on udev event. When hotplugging memory / CPU, multiple udev -# events may be triggered concurrently, and obviously, we don't want -# to restart kdump service for each event. - -# This script will be called by udev, and make sure kdump service is -# restart after all events we are watching are settled. - -# On each call, this script will update try to aquire the $throttle_lock -# The first instance acquired the file lock will keep waiting for events -# to settle and then reload kdump. Other instances will just exit -# In this way, we can make sure kdump service is restarted immediately -# and for exactly once after udev events are settled. - -throttle_lock="/var/lock/kdump-udev-throttle" - -exec 9>$throttle_lock -if [ $? -ne 0 ]; then - echo "Failed to create the lock file! Fallback to non-throttled kdump service restart" - /bin/kdumpctl reload - exit 1 -fi - -flock -n 9 -if [ $? -ne 0 ]; then - echo "Throttling kdump restart for concurrent udev event" - exit 0 -fi - -# Wait for at least 1 second, at most 4 seconds for udev to settle -# Idealy we will have a less than 1 second lag between udev events settle -# and kdump reload -sleep 1 && udevadm settle --timeout 3 - -# Release the lock, /bin/kdumpctl will block and make the process -# holding two locks at the same time and we might miss some events -exec 9>&- - -/bin/kdumpctl reload - -exit 0 diff --git a/kdump.conf.5 b/kdump.conf.5 deleted file mode 100644 index 20b1620..0000000 --- a/kdump.conf.5 +++ /dev/null @@ -1,397 +0,0 @@ -.TH KDUMP.CONF 5 "07/23/2008" "kexec-tools" - -.SH NAME -kdump.conf \- configuration file for kdump kernel. - -.SH DESCRIPTION - -kdump.conf is a configuration file for the kdump kernel crash -collection service. - -kdump.conf provides post-kexec instructions to the kdump kernel. It is -stored in the initrd file managed by the kdump service. If you change -this file and do not want to reboot in order for the changes to take -effect, restart the kdump service to rebuild the initrd. - -For most configurations, you can simply review the examples provided -in the stock /etc/kdump.conf. - -.B NOTE: -For filesystem dumps the dump target must be mounted before building -kdump initramfs. - -kdump.conf only affects the behavior of the initramfs. Please read the -kdump operational flow section of kexec-kdump-howto.txt in the docs to better -understand how this configuration file affects the behavior of kdump. - -.SH OPTIONS - -.B auto_reset_crashkernel -.RS -determine whether to reset kernel crashkernel parameter to the default value -or not when kexec-tools is updated or a new kernel is installed. The default -crashkernel values are different for different architectures and also take the -following factors into consideration, -.IP -\- AMD Secure Memory Encryption (SME) and Secure Encrypted Virtualization (SEV) -.IP -\- Mellanox 5th generation network driver -.IP -\- aarch64 64k kernel -.IP -\- Firmware-assisted dump (FADump) -.PP -Since the kernel crasherkernel parameter will be only reset when kexec-tools is -updated or a new kernel is installed, you need to call "kdumpctl -reset-crashkernel [--kernel=path_to_kernel]" if you want to use the default -value set after having enabled features like SME/SEV for a specific kernel. And -you should also reboot the system for the new crashkernel value to take effect. -Also see kdumpctl(8). -.PP -.RE - -.B raw -.RS -Will dd /proc/vmcore into . Use persistent device names for -partition devices, such as /dev/vg/. -.RE - -.B nfs -.RS -Will mount nfs to , and copy /proc/vmcore to //%HOST-%DATE/, -supports DNS. Note that a fqdn should be used as the server name in the -mount point. -.RE - -.B ssh -.RS -Will save /proc/vmcore through ssh pipe to :/%HOST-%DATE/, -supports DNS. NOTE: make sure user has necessary write permissions on -server and that a fqdn is used as the server name. -.RE - -.B sshkey -.RS -Specify the path of the ssh key to use when dumping via ssh. -The default value is /root/.ssh/kdump_id_rsa. -.RE - -.B -.RS -Will mount -t , and copy /proc/vmcore to -//%HOST_IP-%DATE/. NOTE: can be a device node, label -or uuid. It's recommended to use persistent device names such as -/dev/vg/. Otherwise it's suggested to use label or uuid. -.RE - -.B path -.RS -"path" represents the file system path in which vmcore will be saved. -If a dump target is specified in kdump.conf, then "path" is relative to the -specified dump target. -.PP -Interpretation of "path" changes a bit if the user didn't specify any dump -target explicitly in kdump.conf. In this case, "path" represents the -absolute path from root. The dump target and adjusted path are arrived -at automatically depending on what's mounted in the current system. -.PP -Ignored for raw device dumps. If unset, will use the default "/var/crash". -.RE - -.B core_collector -.RS -This allows you to specify the command to copy the vmcore. -The default is makedumpfile, which on some architectures can drastically reduce -core file size. See /sbin/makedumpfile --help for a list of options. -Note that the -i and -g options are not needed here, as the initrd -will automatically be populated with a config file appropriate -for the running kernel. -.PP -Note 1: About default core collector: -The default core_collector for raw/ssh dump is: -"makedumpfile -F -l --message-level 7 -d 31". -The default core_collector for other targets is: -"makedumpfile -l --message-level 7 -d 31". -Even if core_collector option is commented out in kdump.conf, makedumpfile -is the default core collector and kdump uses it internally. -If one does not want makedumpfile as default core_collector, then they -need to specify one using core_collector option to change the behavior. -.PP -Note 2: If "makedumpfile -F" is used then you will get a flattened format -vmcore.flat, you will need to use "makedumpfile -R" to rearrange the -dump data from standard input to a normal dumpfile (readable with analysis -tools). -ie. "makedumpfile -R vmcore < vmcore.flat" -.PP -Note 3: If specified core_collector simply copy the vmcore file to the -dump target (eg: cp, scp), the vmcore could be significantly large. -Please make sure the dump target has enough space, at leaset larger -than the system's RAM. - -.RE - -.B kdump_post -.RS -This directive allows you to run a specified executable -just after the vmcore dump process terminates. The exit -status of the current dump process is fed to the kdump_post -executable as its first argument($1). Executable can modify -it to indicate the new exit status of succeeding dump process, -.PP -All files under /etc/kdump/post.d are collectively sorted -and executed in lexical order, before binary or script -specified kdump_post parameter is executed. -.PP -Note that scripts written for use with this directive must use the /bin/bash -interpreter. And since these scripts run in kdump enviroment, the reference to -the storage or network device in the scripts should adhere to the section -'Supported dump target types and requirements' in kexec-kdump-howto.txt. - -.RE - -.B kdump_pre -.RS -Works just like the "kdump_post" directive, but instead -of running after the dump process, runs immediately -before. Exit status of this binary is interpreted -as follows: -.PP -0 - continue with dump process as usual -.PP -non 0 - run the final action (reboot/poweroff/halt) -.PP -All files under /etc/kdump/pre.d are collectively sorted and -executed in lexical order, after binary or script specified -kdump_pre parameter is executed. -Even if the binary or script in /etc/kdump/pre.d directory -returns non 0 exit status, the processing is continued. -.PP -Note that scripts written for use with this directive must use the /bin/bash -interpreter. And since these scripts run in kdump enviroment, the reference to -the storage or network device in the scripts should adhere to the section -'Supported dump target types and requirements' in kexec-kdump-howto.txt. - -.RE - -.B extra_bins -.RS -This directive allows you to specify additional -binaries or shell scripts you'd like to include in -your kdump initrd. Generally only useful in -conjunction with a kdump_post binary or script that -relies on other binaries or scripts. -.RE - -.B extra_modules -.RS -This directive allows you to specify extra kernel -modules that you want to be loaded in the kdump -initrd, typically used to set up access to -non-boot-path dump targets that might otherwise -not be accessible in the kdump environment. Multiple -modules can be listed, separated by spaces, and any -dependent modules will automatically be included. -.RE - -.B failure_action -.RS -Action to perform in case dumping to the intended target fails. The default is "reboot". -reboot: Reboot the system (this is what most people will want, as it returns the system -to a normal state). halt: Halt the system and lose the vmcore. poweroff: The system -will be powered down. shell: Drop to a shell session inside the initramfs, from which -you can manually perform additional recovery actions. Exiting this shell reboots the -system by default or performs "final_action". -Note: kdump uses bash as the default shell. dump_to_rootfs: If non-root dump -target is specified, the failure action can be set as dump_to_rootfs. That means when -dumping to target fails, dump vmcore to rootfs from initramfs context and reboot -by default or perform "final_action". -.RE - -.B default -.RS -Same as the "failure_action" directive above, but this directive is obsolete -and will be removed in the future. -.RE - -.B final_action -.RS -Action to perform in case dumping to the intended target succeeds. -Also performed when "shell" or "dump_to_rootfs" failure action finishes. -Each action is same as the "failure_action" directive above. -The default is "reboot". -.RE - -.B force_rebuild <0 | 1> -.RS -By default, kdump initrd will only be rebuilt when necessary. -Specify 1 to force rebuilding kdump initrd every time when kdump service starts. -.RE - -.B force_no_rebuild <0 | 1> -.RS -By default, kdump initrd will be rebuilt when necessary. -Specify 1 to bypass rebuilding of kdump initrd. - -.PP -force_no_rebuild and force_rebuild options are mutually exclusive and -they should not be set to 1 simultaneously. -.RE - -.B dracut_args -.RS -Kdump uses dracut to generate initramfs for second kernel. This option -allows a user to pass arguments to dracut directly. -.RE - - -.B fence_kdump_args -.RS -Command line arguments for fence_kdump_send (it can contain all valid -arguments except hosts to send notification to). -.RE - - -.B fence_kdump_nodes -.RS -List of cluster node(s) except localhost, separated by spaces, to send fence_kdump notification -to (this option is mandatory to enable fence_kdump). -.RE - - -.SH DEPRECATED OPTIONS - -.B net | -.RS -net option is replaced by nfs and ssh options. Use nfs or ssh options -directly. -.RE - -.B options