Commit 30d537f7 authored by Teng Liu's avatar Teng Liu Committed by David Sterba
Browse files

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: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarTeng Liu <27rabbitlt@gmail.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent f0d3b4c7
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -3381,7 +3381,13 @@ static void cache_save_setup(struct btrfs_block_group *block_group,
	}

	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)