[PATCH] btrfs: skip tests that fail when autodefrag is enabled

[email protected] Thu, 25 Jun 2026 20:20:26 +0100
Newsgroups org.kernel.vger.fstests,org.kernel.vger.linux-btrfs
Message-ID <f0dedcfbe5d78d950325b293cfbb9d4fbab49a55.1782406920.git.fdmanana@suse.com>
From: Filipe Manana <[email protected]>

A couple tests, btrfs/004 and btrfs/308, fail if we pass "-o autodefrag"
in MOUNT_OPTIONS, due to changes in extent layouts. So make sure the
tests are skipped if autodefrag is enabled.

Signed-off-by: Filipe Manana <[email protected]>
---
 common/btrfs    | 7 +++++++
 tests/btrfs/004 | 3 +++
 tests/btrfs/308 | 2 ++
 3 files changed, 12 insertions(+)

diff --git a/common/btrfs b/common/btrfs
index 30288f07..a75fbf1c 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -141,6 +141,13 @@ _require_btrfs_no_nodatasum()
 	fi
 }
 
+_require_btrfs_no_autodefrag()
+{
+	if _normalize_mount_options "$MOUNT_OPTIONS" | grep -q "autodefrag"; then
+		_notrun "This test requires autodefrag to be disabled"
+	fi
+}
+
 _require_btrfs_free_space_tree()
 {
 	_scratch_mkfs > /dev/null 2>&1
diff --git a/tests/btrfs/004 b/tests/btrfs/004
index 06eedde2..1c8b06f5 100755
--- a/tests/btrfs/004
+++ b/tests/btrfs/004
@@ -30,6 +30,9 @@ _require_no_large_scratch_dev
 _require_btrfs_command inspect-internal logical-resolve
 _require_btrfs_command inspect-internal inode-resolve
 _require_command "$FILEFRAG_PROG" filefrag
+# Autodefrag will randomly change the extent layout so filefrag can give us
+# different results from what we expect.
+_require_btrfs_no_autodefrag
 
 FILEFRAG_FILTER='
 	if (/blocks? of (\d+) bytes/) {
diff --git a/tests/btrfs/308 b/tests/btrfs/308
index 3c8d410a..c4ccaa0f 100755
--- a/tests/btrfs/308
+++ b/tests/btrfs/308
@@ -22,6 +22,8 @@ _require_btrfs_fs_feature "free_space_tree"
 _require_btrfs_free_space_tree
 _require_btrfs_no_compress
 _require_btrfs_no_nodatacow
+# We test for a specific stripe layout and autodefrag will change it.
+_require_btrfs_no_autodefrag
 
 test $(_get_page_size) -eq 4096 || _notrun "this tests requires 4k pagesize"
 
-- 
2.47.2