I think decoupling sounds a good idea, the squash module just reused dracut's --compress for convinent, a standalone argument should be better.

Tao Liu <ltao@redhat.com> 于 2022年1月17日周一 下午4:46写道:
Dave said another solution, which is to separate the compression
options passed to dracut and dracut-squash.

Currently, when "--compress zstd" has been passed to dracut cmdline,
if squash is available, "--compress zstd" will be delivered to
dracut-squash, which will call mksquashfs and later libzstd. If not,
"--compress zstd" will be delivered to dracut itself, which will call
cmd zstd later. So dracut-squash inherits the compression option from
dracut.

Dave's solution is to decouple dracut and dracut-squash, finding a way
to deliver "--compress zstd'' to dract-squash only, if squash module
available, libzstd will be used, if unavailable, dracut won't  know
"--compress zstd" and default compressor will be used. So we are good.

In addition, according to --help of mksquashfs/dracut, they support
different compressors and options:

For dracut:
gzip/bzip2/lzma/lzo/lz4/xz/zstd with no compression level customization.

For mksquashfs:
gzip/lzma/lzo/lz4/xz/zstd with compression level customization.

If decoupled, dracut and dracut-squash can use different compressors
and compression levels.

Any ideas for this?

Thanks,
Tao Liu

On Fri, Jan 14, 2022 at 7:46 PM RuiRui Yang <ruyang@redhat.com> wrote:
>
>
>
> On Fri, 14 Jan 2022 at 15:50, Tao Liu <ltao@redhat.com> wrote:
>>
>> Previously if users have not specified the compress method for
>> kdump initramfs, "--compress zstd" will be appended to dracut cmdline.
>>
>> It will make dracut to decide: a) if dracut module squash is added,
>> libzstd will be used, b) otherwise cmd zstd will be used. However in
>> kexec-tools we cannot guarantee dracut module squash is added, for
>> example users can set omit_dracutmodules in dracut.conf and etc, so
>> is_squash_available is not able to check is libzstd or cmd zstd
>> been used at runtime.
>>
>> This patch will give "--compress zstd" a try first, if fails, it will
>> just proceed the default compression method, in order to avoid the
>> error prone zstd/libzstd dependence check.
>>
>> Fixes: 7de4a0d ("Set zstd as recommented for kexec-tools")
>
>
> Hi Tao,  not sure if it has been discussed or not,  dracut squash module compress method could be just different from dracut its own.  So now the squash module is depending on dracut's options, if these two are decoupled then it would be better, it could need some dracut fix.  Thoughts?
>
>>
>>
>> Signed-off-by: Tao Liu <ltao@redhat.com>
>> ---
>>
>> v1 -> v2:
>> Modified the commit message
>> Notify user through ddebug if zstd-try fails, and redirect the error
>> message to ddebug as well.
>>
>> ---
>>  kdump-lib.sh |  5 -----
>>  mkdumprd     | 23 ++++++++++++++---------
>>  mkfadumprd   |  9 +++++++--
>>  3 files changed, 21 insertions(+), 16 deletions(-)
>>
>> diff --git a/kdump-lib.sh b/kdump-lib.sh
>> index 2ea51be..6415dda 100755
>> --- a/kdump-lib.sh
>> +++ b/kdump-lib.sh
>> @@ -31,11 +31,6 @@ is_squash_available()
>>         done
>>  }
>>
>> -is_zstd_command_available()
>> -{
>> -       [[ -x "$(command -v zstd)" ]]
>> -}
>> -
>>  perror_exit()
>>  {
>>         derror "$@"
>> diff --git a/mkdumprd b/mkdumprd
>> index 593ec77..0a81dc7 100644
>> --- a/mkdumprd
>> +++ b/mkdumprd
>> @@ -431,15 +431,6 @@ 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
>> -               add_dracut_arg "--compress" "zstd"
>> -       fi
>> -fi
>> -
>>  if [[ -n $extra_modules ]]; then
>>         add_dracut_arg "--add-drivers" "$extra_modules"
>>  fi
>> @@ -457,6 +448,20 @@ if ! is_fadump_capable; then
>>         add_dracut_arg "--no-hostonly-default-device"
>>  fi
>>
>> +if ! have_compression_in_dracut_args; then
>> +       # Here we will first try to compress in zstd, if fails we will proceed
>> +       # the default compress method.
>> +       dracut "${dracut_args[@]}" "--compress" "zstd" "$@" 2> >(ddebug)
>> +       _rc=$?
>> +
>> +       if [[ $_rc -eq 0 ]]; then
>> +               sync
>> +               exit $_rc
>> +       else
>> +               ddebug "Failback to default compress method"
>> +       fi
>> +fi
>> +
>>  dracut "${dracut_args[@]}" "$@"
>>
>>  _rc=$?
>> diff --git a/mkfadumprd b/mkfadumprd
>> index 86dfcee..0d40975 100644
>> --- a/mkfadumprd
>> +++ b/mkfadumprd
>> @@ -64,8 +64,13 @@ fi
>>
>>  # Same as setting zstd in mkdumprd
>>  if ! have_compression_in_dracut_args; then
>> -       if is_squash_available || is_zstd_command_available; then
>> -               _dracut_isolate_args+=(--compress zstd)
>> +       dracut --force --quiet "${_dracut_isolate_args[@]}" "--compress" "zstd" "$@" "$TARGET_INITRD" 2> >(ddebug)
>> +       _rc=$?
>> +
>> +       if [[ $_rc -eq 0 ]]; then
>> +               exit $_rc
>> +       else
>> +               ddebug "Failback to default compress method for fadump"
>>         fi
>>  fi
>>
>> --
>> 2.33.1
>> _______________________________________________
>> kexec mailing list -- kexec@lists.fedoraproject.org
>> To unsubscribe send an email to kexec-leave@lists.fedoraproject.org
>> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
>> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
>> List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
>> Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
_______________________________________________
kexec mailing list -- kexec@lists.fedoraproject.org
To unsubscribe send an email to kexec-leave@lists.fedoraproject.org
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure