From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org, fstests@vger.kernel.org
Subject: [PATCH 2/2] fstests: btrfs: add a new test case that is future-proof
Date: Fri, 26 Dec 2025 08:45:53 +1030 [thread overview]
Message-ID: <20251225221553.19254-3-wqu@suse.com> (raw)
In-Reply-To: <20251225221553.19254-1-wqu@suse.com>
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>
---
tests/btrfs/131 | 5 ++-
tests/btrfs/340 | 103 ++++++++++++++++++++++++++++++++++++++++++++
tests/btrfs/340.out | 15 +++++++
3 files changed, 122 insertions(+), 1 deletion(-)
create mode 100755 tests/btrfs/340
create mode 100644 tests/btrfs/340.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/340 b/tests/btrfs/340
new file mode 100755
index 00000000..0d558422
--- /dev/null
+++ b/tests/btrfs/340
@@ -0,0 +1,103 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 SUSE S.A. All Rights Reserved.
+#
+# FS QA Test 340
+#
+# 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/340.out b/tests/btrfs/340.out
new file mode 100644
index 00000000..d8b99b3b
--- /dev/null
+++ b/tests/btrfs/340.out
@@ -0,0 +1,15 @@
+QA output created by 340
+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.51.2
next prev parent reply other threads:[~2025-12-25 22:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-25 22:15 [PATCH 0/2] fstests: btrfs: make space cache related tests future proof Qu Wenruo
2025-12-25 22:15 ` [PATCH 1/2] fstests: btrfs/131: add explicit v1 space cache requirement Qu Wenruo
2026-01-18 18:30 ` Zorro Lang
2025-12-25 22:15 ` Qu Wenruo [this message]
2026-01-18 18:31 ` [PATCH 2/2] fstests: btrfs: add a new test case that is future-proof Zorro Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251225221553.19254-3-wqu@suse.com \
--to=wqu@suse.com \
--cc=fstests@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox