summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeng Liu <27rabbitlt@gmail.com>2026-03-28 09:40:59 +0300
committerDavid Sterba <dsterba@suse.com>2026-04-07 19:56:08 +0300
commit30d537f723d6f37a8ddfb17fe668bb9808f5b49f (patch)
tree19c61c8c04a34bc96c8d00b7b5b78da2e6f263e8
parentf0d3b4c7b82b6bc8bf23be58150d49ecc51ec897 (diff)
downloadlinux-30d537f723d6f37a8ddfb17fe668bb9808f5b49f.tar.xz
btrfs: replace BUG_ON() with error return in cache_save_setup()
In cache_save_setup(), if create_free_space_inode() succeeds but the subsequent lookup_free_space_inode() still fails on retry, the BUG_ON(retries) will crash the kernel. This can happen due to I/O errors or transient failures, not just programming bugs. Replace the BUG_ON with proper error handling that returns the original error code through the existing cleanup path. The callers already handle this gracefully: disk_cache_state defaults to BTRFS_DC_ERROR, so the space cache simply won't be written for that block group. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Teng Liu <27rabbitlt@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/block-group.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index fa6e49a4ba37..e6f5a17a13e3 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3381,7 +3381,13 @@ again:
}
if (IS_ERR(inode)) {
- BUG_ON(retries);
+ if (retries) {
+ ret = PTR_ERR(inode);
+ btrfs_err(fs_info,
+ "failed to lookup free space inode after creation for block group %llu: %d",
+ block_group->start, ret);
+ goto out_free;
+ }
retries++;
if (block_group->ro)