Commit Graph

331 Commits

Author SHA1 Message Date
Tao Liu
c9f583baa4 kdump-lib.sh: rework nmcli related functions
upstream: fedora
resolves: bz2003832
conflict: none

commit 58d3e6db3a
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 15:20:42 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:53:00 +08:00
Tao Liu
60e5a1e7a5 kdump-lib.sh: replace '[ ]' with '[[ ]]' and get rid of legacy ``
upstream: fedora
resolves: bz2003832
conflict:
    Patch hunk modified for function is_secure_boot_enforced().

commit 30090f3a15
Author: Kairui Song <kasong@redhat.com>
Date:   Mon Sep 13 01:17:05 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:52:36 +08:00
Tao Liu
57daebe2f7 kdump-lib-initramfs.sh: make it POSIX compatible
upstream: fedora
resolves: bz2003832
conflict: none

commit 5debf397fe
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Sep 14 03:04:08 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:46:45 +08:00
Tao Liu
5e60aafcaf dracut-kdump.sh: reformat with shfmt
upstream: fedora
resolves: bz2003832
conflict: none

commit 7c76611abb
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 15 23:10:07 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:46:37 +08:00
Tao Liu
eb6eafaf18 dracut-kdump.sh: make it POSIX compatible
upstream: fedora
resolves: bz2003832
conflict: none

commit b1339c3b8a
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 18 21:06:52 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:46:16 +08:00
Tao Liu
62d6f35de4 dracut-kdump.sh: POSIX doesn't support pipefail
upstream: fedora
resolves: bz2003832
conflict: none

commit 725027b735
Author: Kairui Song <kasong@redhat.com>
Date:   Thu Aug 12 02:55:32 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:46:10 +08:00
Tao Liu
039c1d4dc8 dracut-kdump.sh: Use stat instead of ls to get vmcore size
upstream: fedora
resolves: bz2003832
conflict: none

commit b1c794a2cf
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Sep 14 03:00:48 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:46:04 +08:00
Tao Liu
058c4321a8 dracut-kdump.sh: simplify dump_ssh
upstream: fedora
resolves: bz2003832
conflict: none

commit 7a9823b42e
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Aug 3 13:23:26 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:45:58 +08:00
Tao Liu
e268210244 dracut-kdump.sh: remove add_dump_code
upstream: fedora
resolves: bz2003832
conflict: none

commit 8f89e89071
Author: Kairui Song <kasong@redhat.com>
Date:   Mon Aug 2 01:25:17 2021 +0800

    dracut-kdump.sh: remove add_dump_code

    `add_dump_code "<op>"` is just `DUMP_INSTRUCTION="<op>"`, no need a
    extra wrapper for that.

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:45:52 +08:00
Tao Liu
28cf217362 dracut-kdump.sh: don't put KDUMP_SCRIPT_DIR in PATH
upstream: fedora
resolves: bz2003832
conflict: none

commit 0675edbadb
Author: Kairui Song <kasong@redhat.com>
Date:   Mon Aug 2 01:19:44 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:45:45 +08:00
Tao Liu
f9025ca711 kdump-lib-initramfs.sh: move dump related functions to kdump.sh
upstream: fedora
resolves: bz2003832
conflict: none

commit a1205effaa
Author: Kairui Song <kasong@redhat.com>
Date:   Thu Aug 5 00:59:29 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:45:39 +08:00
Tao Liu
13a24c49ab Merge kdump-error-handler.sh into kdump.sh
upstream: fedora
resolves: bz2003832
conflict: none

commit e7118d1de8
Author: Kairui Song <kasong@redhat.com>
Date:   Mon Aug 2 00:50:22 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:45:31 +08:00
Tao Liu
35519c3eca kdump-lib-initramfs.sh: prepare to be a POSIX compatible lib
upstream: fedora
resolves: bz2003832
conflict: none

commit a5faa052d4
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Sep 14 03:25:46 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:45:15 +08:00
Tao Liu
b494b7f193 bash scripts: reformat with shfmt
upstream: fedora
resolves: bz2003832
conflict:
    function load_kdump_kernel_key() not exist in rhel9,
    so related patch hunk is removed.

commit 0e4b66b1ab
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Sep 14 02:25:40 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:42:45 +08:00
Tao Liu
63308480fc bash scripts: declare and assign separately
upstream: fedora
resolves: bz2003832
conflict: none

commit 4f75e16700
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 18 02:04:45 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:37:15 +08:00
Tao Liu
f6d6b60a6a bash scripts: fix redundant exit code check
upstream: fedora
resolves: bz2003832
conflict: none

commit a4648fc851
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 17:23:16 2021 +0800

    bash scripts: fix redundant exit code check

    As suggested by:
    https://github.com/koalaman/shellcheck/wiki/SC2181

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:35:45 +08:00
Tao Liu
bf4667b866 bash scripts: fix variable quoting issue
upstream: fedora
resolves: bz2003832
conflict:
    function remove_kdump_kernel_key() not presented in rhel9,
    so related patch hunk are removed.

commit 86538ca6e2
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 17:21:41 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:27:55 +08:00
Tao Liu
c373a2c582 Don't use die in dracut-module-setup.sh
upstream: fedora
resolves: bz2003832
conflict: none

commit 8b4b7bf808
Author: Coiby Xu <coxu@redhat.com>
Date:   Fri Mar 26 10:22:09 2021 +0800

    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 <coxu@redhat.com>
    Acked-by: Kairui Song <kasong@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:22:55 +08:00
Tao Liu
dcb59c30d5 bash scripts: replace '[ ]' with '[[ ]]' for bash scripts
upstream: fedora
resolves: bz2003832
conflict:
    function load_kdump_kernel_key() not presented in rhel9,
    so related patch hunk are removed.

commit 70978c00e5
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 17:20:51 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:13:59 +08:00
Tao Liu
20c694278f mkdumprd: display the absolute path of dump location in the check_user_configured_target()
upstream: fedora
resolves: bz2003832
conflict: none

commit 2d9504c4a4
Author: Lianbo Jiang <lijiang@redhat.com>
Date:   Tue Jun 1 18:33:44 2021 +0800

    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: "<mount path>/<path>". To fix it, let's extend the relative
    pathname to the absolute pathname in check_user_configured_target().

    Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
    Acked-by: Kairui Song <kasong@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 21:10:25 +08:00
Tao Liu
98e1935293 Don't iterate the whole /sys/devices just to find drm device
upstream: fedora
resolves: bz2003832
conflict: none

commit c6021648f1
Author: Kairui Song <kasong@redhat.com>
Date:   Fri Mar 19 18:21:11 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Pingfan Liu <piliu@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 20:48:26 +08:00
Tao Liu
b9cefb4161 mkdumprd: prompt the user to install nfs-utils when mounting NFS fs failed
upstream: fedora
resolves: bz2003832
conflict: none

commit e5a745ce77
Author: Coiby Xu <coxu@redhat.com>
Date:   Sat Feb 20 11:55:52 2021 +0800

    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.<type> 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 <coxu@redhat.com>
    Acked-by: Kairui Song <kasong@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 20:41:42 +08:00
Tao Liu
16c2821171 bash scripts: use $(...) notation instead of legacy ...
upstream: fedora
resolves: bz2003832
conflict: none

commit 54cc5c44be
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 01:48:52 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 20:39:50 +08:00
Tao Liu
67611bba2a bash scripts: always use "read -r"
upstream: fedora
resolves: bz2003832
conflict: none

commit a416930706
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:50:30 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 20:39:17 +08:00
Tao Liu
d07b20d718 bash scripts: get rid of unnecessary sed calls
upstream: fedora
resolves: bz2003832
conflict: none

commit fdfad3102e
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:46:27 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 20:39:09 +08:00
Tao Liu
480de7c63d bash scripts: get rid of expr and let
upstream: fedora
resolves: bz2003832
conflict: none

commit c4d85142be
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:18:59 2021 +0800

    bash scripts: get rid of expr and let

    As suggested by:
    https://github.com/koalaman/shellcheck/wiki/SC2219

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 20:39:02 +08:00
Tao Liu
e07098aa14 bash scripts: remove useless cat
upstream: fedora
resolves: bz2003832
conflict:
    load_kdump_kernel_key() didn't present in rhel9,
    so removed the patch for it.

commit 6d45257cc1
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:14:00 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-09 20:38:55 +08:00
Tao Liu
6d930905d5 dracut-module-setup.sh: remove surrounding $() for subshell
upstream: fedora
resolves: bz2003832
conflict: none

commit 3b0157197b
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Sep 8 15:15:44 2021 +0800

    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 <kasong@redhat.com>
    Suggested-by: Coiby Xu <coxu@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:15:26 +08:00
Tao Liu
9abf44a082 dracut-module-setup.sh: make iscsi check fail early if cd failed
upstream: fedora
resolves: bz2003832
conflict: none

commit 67e559a6b9
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 16:29:55 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:15:06 +08:00
Tao Liu
72c3befcb8 dracut-module-setup.sh: fix a loop over ls issue
upstream: fedora
resolves: bz2003832
conflict: none

commit 3b2fa982bb
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 16:16:44 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:14:44 +08:00
Tao Liu
057e505536 dracut-module-setup.sh: fix a ambiguous variable reference
upstream: fedora
resolves: bz2003832
conflict: none

commit dfe7555323
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:51:34 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:14:24 +08:00
Tao Liu
c8faddc4f8 dracut-module-setup.sh: use "*" to expend array as string
upstream: fedora
resolves: bz2003832
conflict: none

commit da3ad9cbda
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:47:43 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:14:08 +08:00
Tao Liu
c0cbd45726 dracut-module-setup.sh: fix _bondoptions wrong references
upstream: fedora
resolves: bz2003832
conflict: none

commit 49dd4fcdbb
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:41:10 2021 +0800

    dracut-module-setup.sh: fix _bondoptions wrong references

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:13:55 +08:00
Tao Liu
3fb4383a9c dracut-module-setup.sh: remove an unused variable
upstream: fedora
resolves: bz2003832
conflict: none

commit ba7aa447b2
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 14:29:10 2021 +0800

    dracut-module-setup.sh: remove an unused variable

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:13:40 +08:00
Tao Liu
37b61ee43a dracut-module-setup.sh: rework kdump_get_ip_route_field
upstream: fedora
resolves: bz2003832
conflict: none

commit 46542ccda5
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 02:59:43 2021 +0800

    dracut-module-setup.sh: rework kdump_get_ip_route_field

    Avoid duplicated echo / cut / grep call, just use sed.

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:13:28 +08:00
Tao Liu
caa2405338 mkfadumprd: make _dracut_isolate_args an array
upstream: fedora
resolves: bz2003832
conflict: none

commit 982205d607
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 03:06:57 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:13:10 +08:00
Tao Liu
1539061bbe mkdumprd: use array to store ssh arguments in mkdir_save_path_ssh
upstream: fedora
resolves: bz2003832
conflict: none

commit 3a4b0351d0
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 18 15:45:20 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:12:53 +08:00
Tao Liu
9658700a8b mkdumprd: remove an awk call in get_fs_size
upstream: fedora
resolves: bz2003832
conflict: none

commit c486b1fa30
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Sep 7 14:42:30 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:12:28 +08:00
Tao Liu
033d4cf5fb mkdumprd: fix multiple issues with get_ssh_size
upstream: fedora
resolves: bz2003832
conflict: none

commit d6449e7293
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 17:15:42 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:12:12 +08:00
Tao Liu
0d42485888 mkdumprd: remove some redundant echo
upstream: fedora
resolves: bz2003832
conflict: none

commit e4c7b5bbf5
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 03:53:35 2021 +0800

    mkdumprd: remove some redundant echo

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:11:52 +08:00
Tao Liu
dd08f1bddd mkdumprd: make dracut_args an array again
upstream: fedora
resolves: bz2003832
conflict: none

commit 227fc2bc7d
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 03:50:04 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:11:30 +08:00
Tao Liu
514b4f0679 mkdumprd: use kdump_get_conf_val to read config values
upstream: fedora
resolves: bz2003832
conflict: none

commit 075e62252e
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 01:58:04 2021 +0800

    mkdumprd: use kdump_get_conf_val to read config values

    Simplify the code and cover more corner cases.

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:11:00 +08:00
Tao Liu
e35e4054ca kdumpctl: refine grep usage
upstream: fedora
resolves: bz2003832
conflict: none

commit 80525aface
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 15:44:02 2021 +0800

    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 <kasong@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:10:36 +08:00
Tao Liu
6c43817d23 kdumpctl: fix fragile loops over find output
upstream: fedora
resolves: bz2003832
conflict: none

commit dfb76467c9
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 16:22:17 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:10:13 +08:00
Tao Liu
6afe4ea23f kdumpctl: use kdump_get_conf_val to read config values
upstream: fedora
resolves: bz2003832
conflict: none

commit 01613b7211
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Aug 3 22:50:02 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:09:49 +08:00
Tao Liu
9a937b5e22 kdump-lib.sh: use kdump_get_conf_val to read config values
upstream: fedora
resolves: bz2003832
conflict: none

commit ab1ef78aa2
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 4 01:18:48 2021 +0800

    kdump-lib.sh: use kdump_get_conf_val to read config values

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:09:16 +08:00
Tao Liu
14205c1d6f kdump-lib.sh: add a config value retrive helper
upstream: fedora
resolves: bz2003832
conflict: none

commit 09ccf88405
Author: Kairui Song <kasong@redhat.com>
Date:   Mon Aug 16 23:25:14 2021 +0800

    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 <config> | 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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:08:50 +08:00
Tao Liu
67b8dd1cb8 kdump-lib.sh: add a config format and read helper
upstream: fedora
resolves: bz2003832
conflict: none

commit a0282ab22c
Author: Kairui Song <kasong@redhat.com>
Date:   Tue Aug 3 19:49:51 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:08:22 +08:00
Tao Liu
45ebaec123 Add a .editorconfig file
upstream: fedora
resolves: bz2003832
conflict: none

commit bcb1176ec6
Author: Kairui Song <kasong@redhat.com>
Date:   Fri Jul 30 01:08:30 2021 +0800

    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 <kasong@redhat.com>
    Acked-by: Pingfan Liu <piliu@redhat.com>
    Acked-by: Philipp Rudo <prudo@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
2021-11-03 16:06:56 +08:00
Tao Liu
7ccb7e18e7 Remove hard requirement on grubby
Resolves: bz2014626
Upstream: Fedora
Conflict: None

commit 7ddda7e6d0
Author: Kairui Song <kasong@redhat.com>
Date:   Wed Aug 18 22:25:22 2021 +0800

    Remove hard requirement on grubby

    Downgrade to "Recommends:" as suggested by CoreOS team.

    Signed-off-by: Kairui Song <kasong@redhat.com>
    Acked-by: Tao Liu <ltao@redhat.com>

Signed-off-by: Tao Liu <ltao@redhat.com>
Signed-off-by: Timothée Ravier <travier@redhat.com>
2021-10-28 13:26:19 +08:00