Re: [PATCH 2/9] fstests: add _mkfs_scratch_clone() helper

Zorro Lang
2026-03-09T19:13:26Z

On Thu, Feb 26, 2026 at 10:41:43PM +0800, Anand Jain wrote:
> Introduce _mkfs_scratch_clone() to mkfs the scratch device and clone it to
> the next device in SCRATCH_DEV_POOL.
>
> Signed-off-by: Anand Jain <asj@kernel.org>
> ---
> common/rc | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/common/rc b/common/rc
> index 9db8b3e88996..2253438ef0f6 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -1503,6 +1503,38 @@ _scratch_resvblks()
> esac
> }
>
> +_scratch_mkfs_sized_clone()
> +{
> + local devs=($SCRATCH_DEV_POOL)
> + local scratch_data="$1"
> + local size=$(_small_fs_size_mb 128) # Smallest possible
> +
> + size=$((size * 1024 * 1024))
> +
> + # make sure there are two devices
> + if [ "${#devs[@]}" -ne 2 ]; then

What about if ${#devs[@]} > 2 ?

> + _notrun "Test requires exactly 2 devices"
> + fi
> +
> + case "$FSTYP" in
> + "btrfs")
> + _scratch_mkfs_sized $size
> + _scratch_mount
> + $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/sv1
> + _scratch_unmount
> + ;;
> + "xfs"|"ext4")
> + _scratch_mkfs_sized $size
> + ;;
> + *)
> + _notrun "fstests clone op unsupported for FS $FSTYP"
> + ;;
> + esac
> +
> + # clone SCRATCH_DEV devs[0] to devs[1].
> + dd if=$SCRATCH_DEV of=${devs[1]} bs=$size status=none count=1 || \
> + _fail "Clone failed"

I'm wondering if we absolutely need to use SCRATCH_DEV_POOL for this test. Could we clone SCRATCH_DEV
to an image file instead? Or would it be feasible to simply run the test using two image files?

Thanks,
Zorro

> +}
>
> # Repair scratch filesystem. Returns 0 if the FS is good to go (either no
> # errors found or errors were fixed) and nonzero otherwise; also spits out
> --
> 2.43.0
>
>