mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] btrfs: clear free space tree state on rebuild failure
@ 2026-09-15 14:48 Guanghui Yang
  2026-09-15 18:36 ` Boris Burkov
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Guanghui Yang @ 2026-09-15 14:48 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, mason, linux-kernel, stable, Guanghui Yang

btrfs_rebuild_free_space_tree() sets
BTRFS_FS_CREATING_FREE_SPACE_TREE and
BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED before rebuilding the free space
tree. Several error paths return without clearing these flags.

This leaves the flags set on the live filesystem and affects delayed
reference processing and free-space caching. Clear both flags on all
free space tree rebuild failure paths.

Fixes: 1d6a4fc85717 ("btrfs: make clear_cache mount option to rebuild FST without disabling it")
Cc: stable@vger.kernel.org # 6.4+
Assisted-by: Codex:gpt-5
Tested: make -j$(nproc) fs/btrfs/free-space-tree.o
Signed-off-by: Guanghui Yang <3497809730@qq.com>
---
 fs/btrfs/free-space-tree.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 1b3d82ae3de8..1410da2766a9 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1353,7 +1353,7 @@ int btrfs_rebuild_free_space_tree(struct btrfs_fs_info *fs_info)
 	if (unlikely(ret)) {
 		btrfs_abort_transaction(trans, ret);
 		btrfs_end_transaction(trans);
-		return ret;
+		goto out_clear;
 	}
 
 	node = rb_first_cached(&fs_info->block_group_cache_tree);
@@ -1371,14 +1371,16 @@ int btrfs_rebuild_free_space_tree(struct btrfs_fs_info *fs_info)
 		if (unlikely(ret)) {
 			btrfs_abort_transaction(trans, ret);
 			btrfs_end_transaction(trans);
-			return ret;
+			goto out_clear;
 		}
 next:
 		if (btrfs_should_end_transaction(trans)) {
 			btrfs_end_transaction(trans);
 			trans = btrfs_start_transaction(free_space_root, 1);
-			if (IS_ERR(trans))
-				return PTR_ERR(trans);
+			if (IS_ERR(trans)) {
+				ret = PTR_ERR(trans);
+				goto out_clear;
+			}
 		}
 		node = rb_next(node);
 	}
@@ -1390,6 +1392,11 @@ int btrfs_rebuild_free_space_tree(struct btrfs_fs_info *fs_info)
 	ret = btrfs_commit_transaction(trans);
 	clear_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags);
 	return ret;
+
+out_clear:
+	clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags);
+	clear_bit(BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED, &fs_info->flags);
+	return ret;
 }
 
 static int __add_block_group_free_space(struct btrfs_trans_handle *trans,

base-commit: 587858367581b9c55c3690f4e63382ad622719d4
-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-09-16 17:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15 14:48 [PATCH] btrfs: clear free space tree state on rebuild failure Guanghui Yang
2026-09-15 18:36 ` Boris Burkov
2026-09-15 22:16 ` Qu Wenruo
2026-09-16  2:38 ` [PATCH v2] btrfs: clear free space tree creation " Guanghui Yang
2026-09-16  2:50   ` Qu Wenruo
2026-09-16  5:16   ` [PATCH v3] " Guanghui Yang
2026-09-16  5:28     ` Qu Wenruo
2026-09-16 17:06     ` Boris Burkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®