Commit Graph

1408 Commits

Author SHA1 Message Date
Kairui Song
a416930706 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>
2021-09-14 03:25:29 +08:00
Kairui Song
fdfad3102e 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>
2021-09-14 03:25:29 +08:00
Kairui Song
c4d85142be 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>
2021-09-14 03:25:29 +08:00
Kairui Song
6d45257cc1 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>
2021-09-14 03:25:29 +08:00
Kairui Song
3b0157197b 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>
2021-09-14 03:25:29 +08:00
Kairui Song
67e559a6b9 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>
2021-09-14 03:25:29 +08:00
Kairui Song
3b2fa982bb 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>
2021-09-14 03:25:29 +08:00
Kairui Song
dfe7555323 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>
2021-09-14 03:25:29 +08:00
Kairui Song
da3ad9cbda 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>
2021-09-14 03:25:29 +08:00
Kairui Song
49dd4fcdbb dracut-module-setup.sh: fix _bondoptions wrong references
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
2021-09-14 03:25:29 +08:00
Kairui Song
ba7aa447b2 dracut-module-setup.sh: remove an unused variable
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
2021-09-14 03:25:29 +08:00
Kairui Song
46542ccda5 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>
2021-09-14 03:25:29 +08:00
Kairui Song
982205d607 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>
2021-09-14 03:25:29 +08:00
Kairui Song
3a4b0351d0 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>
2021-09-14 03:25:29 +08:00
Kairui Song
c486b1fa30 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>
2021-09-14 03:25:29 +08:00
Kairui Song
d6449e7293 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>
2021-09-14 03:25:29 +08:00
Kairui Song
e4c7b5bbf5 mkdumprd: remove some redundant echo
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
2021-09-14 03:25:29 +08:00
Kairui Song
227fc2bc7d 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>
2021-09-14 03:25:29 +08:00
Kairui Song
075e62252e 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>
2021-09-14 03:25:29 +08:00
Kairui Song
80525aface 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>
2021-09-14 03:25:29 +08:00
Kairui Song
dfb76467c9 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
2021-09-14 03:25:29 +08:00
Kairui Song
01613b7211 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>
2021-09-14 03:25:29 +08:00
Kairui Song
ab1ef78aa2 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>
2021-09-14 03:25:29 +08:00
Kairui Song
09ccf88405 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>
2021-09-14 03:25:29 +08:00
Kairui Song
a0282ab22c 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>
2021-09-14 03:25:29 +08:00
Kairui Song
bcb1176ec6 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: Kairui Song <kasong@redhat.com>
2021-09-14 03:25:25 +08:00
Adam Williamson
5270d40dd0 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.
2021-08-31 16:07:51 -07:00
Kairui Song
6c390b70e8 Release 2.0.22-6
Also fix a format error in changelog.

Signed-off-by: Kairui Song <kasong@redhat.com>
2021-08-20 20:14:27 +08:00
Kairui Song
7ddda7e6d0 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>
2021-08-20 16:13:25 +08:00
Kairui Song
097059dedc Clear old crashkernl=auto in comment and doc
Acked-by: Pingfan Liu <piliu@redhat.com>
Signed-off-by: Kairui Song <kasong@redhat.com>
2021-08-05 17:54:20 +08:00
Hari Bathini
146f662622 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 <hbathini@linux.ibm.com>
Acked-by: Kairui Song <kasong@redhat.com>
2021-07-31 19:40:14 +08:00
Fedora Release Engineering
152cf5e46c - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2021-07-22 09:42:58 +00:00
Coiby Xu
b2bbb54d89 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 7d47251568
       ("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 <jieli@redhat.com>
Signed-off-by: Coiby Xu <coxu@redhat.com>
t Acked-by: Kairui Song <kasong@redhat.com>
2021-07-21 17:10:28 +08:00
Kairui Song
660cf4ac03 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 <kasong@redhat.com>
Acked-by: Coiby Xu <coxu@redhat.com>
2021-07-21 15:40:38 +08:00
Kairui Song
7435ecf3c4 Update crashkernel-howto.txt
Fix some grammar issues.

Signed-off-by: Kairui Song <kasong@redhat.com>
2021-07-21 14:05:42 +08:00
Hari Bathini
71b7a2f47c 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 <hbathini@linux.ibm.com>
Reviewed-by: Pingfan Liu <piliu@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
2021-07-21 10:53:59 +08:00
Philipp Rudo
914a856c66 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 <prudo@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
2021-07-20 15:57:05 +08:00
Kairui Song
bcd8d6a47b kdumpctl: fix a typo
Recommanded -> Recommended

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Coiby Xu <coxu@redhat.com>
2021-07-20 15:57:05 +08:00
Zbigniew Jędrzejewski-Szmek
c894022e9b 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.)
2021-07-18 16:36:52 +00:00
Kairui Song
7b7ddaba88 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 <kasong@redhat.com>
Acked-by: Pingfan Liu <piliu@redhat.com>
2021-07-14 02:04:06 +08:00
Coiby Xu
231a75ac1b Revert "Revert "x86_64: enable the kexec file load by default""
This reverts commit 073c30973c, 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 <coxu@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
2021-07-14 02:03:10 +08:00
Kairui Song
2603ba7187 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 <kasong@redhat.com>
Acked-by: Coiby Xu <coxu@redhat.com>
2021-07-12 16:53:34 +08:00
Kairui Song
7dbbb4bb31 Add a crashkernel-howto.txt doc
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
2021-07-08 15:36:36 +08:00
Kairui Song
6463641935 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 <kasong@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
2021-07-08 15:36:32 +08:00
Kairui Song
86130ec10f 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 <kasong@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
2021-07-08 15:18:45 +08:00
Kairui Song
017903c3c4 Revert "kdump-lib.sh: Remove is_atomic"
Now we need this helper again, for `reset-crashkernel`

This reverts commit ff46cfb19e.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Baoquan He <bhe@redhat.com>
2021-07-08 15:18:00 +08:00
Kairui Song
97930d3cca 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 <kasong@redhat.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
2021-06-30 17:28:45 +08:00
Kairui Song
bf6671b60d 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 <kasong@redhat.com>
Acked-by: Hari Bathini <hbathini@linux.ibm.com>
2021-06-30 17:27:02 +08:00
Hari Bathini
fa9201b240 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 <hbathini@linux.ibm.com>
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
2021-06-29 21:35:58 +08:00
Kairui Song
c4749f9c57 Release 2.0.22-4
Signed-off-by: Kairui Song <kasong@redhat.com>
2021-06-29 21:24:19 +08:00