]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
fstests: btrfs: add a new test case that is future-proof
authorQu Wenruo <wqu@suse.com>
Thu, 25 Dec 2025 22:15:53 +0000 (08:45 +1030)
committerZorro Lang <zlang@kernel.org>
Sun, 25 Jan 2026 16:05:29 +0000 (00:05 +0800)
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 <wqu@suse.com>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
tests/btrfs/131
tests/btrfs/342 [new file with mode: 0755]
tests/btrfs/342.out [new file with mode: 0644]

index 026d11e6eb0aeba1ab7ca836181177c36e464504..b54b8326a9306ae11b38c8ee4ca86adf84828ba8 100755 (executable)
@@ -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 (executable)
index 0000000..e88b47e
--- /dev/null
@@ -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 (file)
index 0000000..3a289a7
--- /dev/null
@@ -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