Hi Tao,
Thanks for adding code comment.
Acked-by: Coiby Xu <coxu(a)redhat.com>
Btw, it just occurs to me what if the user chooses to use zstd in kdump.conf
but the zstd command is not available? Of course this is not the problem of
this patch.
On Mon, Jan 10, 2022 at 09:51:16PM +0800, Tao Liu wrote:
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 <ltao(a)redhat.com>
---
v1 -> v2: Add code comment. Code refactor in mkfadumprd.
---
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 6415dda..2ea51be 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 90f9355..367929a 100644
--- a/kexec-tools.spec
+++ b/kexec-tools.spec
@@ -71,7 +71,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
--
2.33.1
--
Best regards,
Coiby