Re: [PATCH 1/3] btrfs-progs: tests: fix the wrong kernel version check

David Sterba
2022-10-06T15:25:46Z

On Wed, Oct 05, 2022 at 10:25:12AM +0800, Qu Wenruo wrote:
> [BUG]
> After upgrading to kernel v6.0-rc, btrfs-progs selftest mkfs/001 no
> longer checks single device RAID0 and other new features introduced in
> v5.13:
>
> # make TEST=001\* test-mkfs
> [TEST] mkfs-tests.sh
> [TEST/mkfs] 001-basic-profiles
> $ grep -IR "RAID0\/1" tests/mkfs-tests-results.txt
> ^^^ No output
>
> [CAUSE]
> The existing check_min_kernel_version() is doing an incorrect check.
>
> The old check looks like this:
>
> [ "$unamemajor" -lt "$argmajor" ] || return 1
> [ "$unameminor" -lt "$argminor" ] || return 1
> return 0
>
> For 6.0-rc kernels, we have the following values for mkfs/001
>
> $unamemajor = 6
> $unameminor = 0
> $argmajor = 5
> $argminor = 12
>
> The first check doesn't exit immediately, as 6 > 5.
> Then we check the minor, which is already incorrect.
>
> If our major is larger than target major, we should exit immediate with
> 0.
>
> [FIX]
> Fix the check and add extra comment.
>
> Personally speaking I'm not a fan or short compare and return, thus all
> the checks will explicit "if []; then fi" checks.

Agreed the explicit if should be used in most cases, what is probably ok
a 'command || _fail' pattern for simple commands. I try to unify the
shell coding style in new patches but some bits may slip through.