From bc74aaf6859c097439530505dc25fc06dce77c9a Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 26 Dec 2025 08:45:53 +1030 Subject: [PATCH] fstests: btrfs: add a new test case that is future-proof Btrfs' v1 space cache is marked deprecated since commit 1e7bec1f7d65 ("btrfs: emit a warning about space cache v1 being deprecated"), and soon the v1 space cache mount option will be fully dropped. Furthermore existing features like block-group-tree, zoned, and bs != ps support are all rejecting v1 space cache or forcing the switch to v2 space cache. The existing btrfs/131 is not going to handle the future well, and that test case is mostly for LTS kernel testing now. Add a new test case that is completely v1 cache free, so that it will support the future where v1 cache is completely dropped, meanwhile still keep the coverage for v2 cache and nospace_cache mount options. Signed-off-by: Qu Wenruo Reviewed-by: Zorro Lang Signed-off-by: Zorro Lang --- tests/btrfs/131 | 5 ++- tests/btrfs/342 | 103 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/342.out | 15 +++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100755 tests/btrfs/342 create mode 100644 tests/btrfs/342.out diff --git a/tests/btrfs/131 b/tests/btrfs/131 index 026d11e6..b54b8326 100755 --- a/tests/btrfs/131 +++ b/tests/btrfs/131 @@ -4,7 +4,10 @@ # # FS QA Test 131 # -# Test free space tree mount options. +# Test free space tree mount options, 3 options involved: +# - No space cache +# - Old (deprecated) v1 space cache +# - New (default) v2 space cache # . ./common/preamble _begin_fstest auto quick diff --git a/tests/btrfs/342 b/tests/btrfs/342 new file mode 100755 index 00000000..e88b47e0 --- /dev/null +++ b/tests/btrfs/342 @@ -0,0 +1,103 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2025 SUSE S.A. All Rights Reserved. +# +# FS QA Test No. 342 +# +# Test free space tree mount options, for newer kernels with only 2 options involed: +# - No space cache +# - New (default) v2 space cache +# +. ./common/preamble +_begin_fstest auto quick + +_require_scratch +_require_btrfs_command inspect-internal dump-super +_require_btrfs_fs_feature free_space_tree + +# The block-group-tree feature relies on v2 cache, thus it doesn't support +# "nospace_cache" mount option. +_require_btrfs_no_block_group_tree + +mkfs_nocache() +{ + _scratch_mkfs >/dev/null 2>&1 + _scratch_mount -o clear_cache,nospace_cache + _scratch_unmount +} + +mkfs_v2() +{ + _scratch_mkfs >/dev/null 2>&1 + _scratch_mount -o space_cache=v2 + _scratch_unmount +} + +check_fst_compat() +{ + compat_ro="$($BTRFS_UTIL_PROG inspect-internal dump-super "$SCRATCH_DEV" | \ + sed -rn 's/^compat_ro_flags\s+(.*)$/\1/p')" + if ((compat_ro & 0x1)); then + echo "free space tree is enabled" + else + echo "free space tree is disabled" + fi +} + +# Mount options might interfere. +export MOUNT_OPTIONS="" + +# When the free space tree is not enabled: +# -o space_cache=v2: enable the free space tree +# -o clear_cache,space_cache=v2: clear the old space cache and enable the free space tree +# We don't check the no options case or plain space_cache as that will change +# in the future to turn on space_cache=v2. + +mkfs_nocache +echo "Using no space cache" +_scratch_mount -o nospace_cache +check_fst_compat +_scratch_unmount + +mkfs_nocache +echo "Enabling free space tree" +_scratch_mount -o space_cache=v2 +check_fst_compat +_scratch_unmount + +# When the free space tree is enabled: +# -o nospace_cache: error +# no options, -o space_cache=v2: keep using the free space tree +# -o clear_cache, -o clear_cache,space_cache=v2: clear and recreate the free space tree +# -o clear_cache,nospace_cache: clear the free space tree + +mkfs_v2 +echo "Trying to mount without free space tree" +_try_scratch_mount -o nospace_cache >/dev/null 2>&1 || echo "mount failed" + +mkfs_v2 +echo "Mounting existing free space tree" +_scratch_mount +check_fst_compat +_scratch_unmount +_scratch_mount -o space_cache=v2 +check_fst_compat +_scratch_unmount + +mkfs_v2 +echo "Recreating free space tree" +_scratch_mount -o clear_cache,space_cache=v2 +check_fst_compat +_scratch_unmount +mkfs_v2 +_scratch_mount -o clear_cache +check_fst_compat +_scratch_unmount + +mkfs_v2 +echo "Disabling free space tree" +_scratch_mount -o clear_cache,nospace_cache +check_fst_compat +_scratch_unmount + +_exit 0 diff --git a/tests/btrfs/342.out b/tests/btrfs/342.out new file mode 100644 index 00000000..3a289a74 --- /dev/null +++ b/tests/btrfs/342.out @@ -0,0 +1,15 @@ +QA output created by 342 +Using no space cache +free space tree is disabled +Enabling free space tree +free space tree is enabled +Trying to mount without free space tree +mount failed +Mounting existing free space tree +free space tree is enabled +free space tree is enabled +Recreating free space tree +free space tree is enabled +free space tree is enabled +Disabling free space tree +free space tree is disabled -- 2.47.3