[PATCH v2] kdumpctl: sync the $TARGET_INITRD after rebuild
by Lichen Liu
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 <lichliu(a)redhat.com>
---
kdumpctl | 4 +++-
mkdumprd | 4 ----
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 9fd76ac..8ad47bf 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
--
2.27.0
2 years, 1 month
[RFC 0/8] unit tests with ShellSpec
by Coiby Xu
Potential benefits brought by unit tests
=======================================
- catch as many bugs as possible and catch them as early as possible
- improve the code quality and make the code robust
- Keep API stable
- prevent regressions from change during the development and in the future
(it's quite annoying to solve one problem only to find another cropping up)
- make it easy for code review because of concrete test cases
Why ShellSpec
=============
ShellSpec [1] is chosen for the following benefits,
- rich features: to name a few
- mocking
- Parameterized tests
- code coverage
- good documentation and examples
For the full comparison between shellspec and other frameworks, please
refer to [2].
How to run the tests
====================
After installing shellspec and optionally kcov
$ curl -fsSL https://git.io/shellspec | sh
$ sudo dnf install kcov
1. go to the root of this repo
2. create a file with _spec as suffix in the spec folder, e.g. spec/kdumpctl_spec.sh
3. run shellspec
shellspec --kcov --kcov-options "--include-pattern=kdumpctl,kdump-lib.sh,kdump-lib-initramfs.sh,kdump-logger.sh"
Running: /bin/sh [bash 5.1.0(1)-release]
................................................................
Finished in 11.15 seconds (user 6.97 seconds, sys 9.54 seconds)
64 examples, 0 failures
Code covered: 16.08%, Executed lines: 224, Instrumented lines: 1393
[1] https://github.com/shellspec/shellspec
[2] https://github.com/dodie/testing-in-bash#detailed-comparision
Coiby Xu (8):
unit tests: prepare for kdumpctl and kdump-lib.sh to be unit-tested
unit tests: add tests for get_grub_kernel_boot_parameter
unit tests: add tests for get_dump_mode_by_fadump_val
unit tests: add tests for kdumpctl read_proc_environ_var and
_is_osbuild
unit tests: add tests for
_{add,remove,read}_kernel_arg_in_grub_etc_default in kdumpctl
unit tests: add tests for "kdumpctl reset-crashkernel"
unit tests: add tests for kdump_get_conf_val in kdump-lib-initramfs.sh
unit tests: add check_config with with the default kdump.conf
.shellspec | 0
kdump-lib.sh | 7 +-
kdumpctl | 24 +-
spec/kdump-lib-initramfs_spec.sh | 41 ++++
spec/kdumpctl_general_spec.sh | 175 ++++++++++++++
spec/kdumpctl_reset_crashkernel_spec.sh | 216 ++++++++++++++++++
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 +
11 files changed, 484 insertions(+), 9 deletions(-)
create mode 100644 .shellspec
create mode 100644 spec/kdump-lib-initramfs_spec.sh
create mode 100644 spec/kdumpctl_general_spec.sh
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
--
2.34.1
2 years, 1 month
[PATCH] kdumpctl: sync the $TARGET_INITRD after rebuild
by Lichen Liu
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.
Signed-off-by: Lichen Liu <lichliu(a)redhat.com>
---
kdumpctl | 2 ++
mkdumprd | 1 -
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/kdumpctl b/kdumpctl
index 9fd76ac..fa83c05 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
}
diff --git a/mkdumprd b/mkdumprd
index 593ec77..d5f8945 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -460,5 +460,4 @@ fi
dracut "${dracut_args[@]}" "$@"
_rc=$?
-sync
exit $_rc
--
2.27.0
2 years, 1 month
[PATCH v4 1/2] address the case where there are multiple values for the same kernel arg
by Coiby Xu
When updating the kernel command line in /etc/default/grub, grubby only
replaces a given entry if it is the last entry on the command line.
In all other cases it appends a new entry to it. This behavior makes it
quite likely that 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.
Reported-by: Philipp Rudo <prudo(a)redhat.com>
Suggested-by: Philipp Rudo <prudo(a)redhat.com>
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
kdumpctl | 54 ++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 40 insertions(+), 14 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 9fd76ac..978aee1 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
--
2.34.1
2 years, 1 month