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

Anand Jain
2026-02-26T14:42:04Z

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
+ _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"
+}

# 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