* [PATCH v2] btrfs: replace BUG_ON() with error return in cache_save_setup()
@ 2026-03-28 6:40 Teng Liu
2026-03-28 7:13 ` Qu Wenruo
0 siblings, 1 reply; 2+ messages in thread
From: Teng Liu @ 2026-03-28 6:40 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba, clm, wqu, linux-kernel, Teng Liu
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.
Signed-off-by: Teng Liu <27rabbitlt@gmail.com>
---
Changes in v2:
- Use btrfs_err() instead of btrfs_debug() (Qu Wenruo)
- Use PTR_ERR(inode) instead of hardcoded -EIO (Qu Wenruo)
- Include error code in the log message (Qu Wenruo)
fs/btrfs/block-group.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index ebf507909..89bfc9db0 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -3343,7 +3343,13 @@ static int 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)
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] btrfs: replace BUG_ON() with error return in cache_save_setup()
2026-03-28 6:40 [PATCH v2] btrfs: replace BUG_ON() with error return in cache_save_setup() Teng Liu
@ 2026-03-28 7:13 ` Qu Wenruo
0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2026-03-28 7:13 UTC (permalink / raw)
To: Teng Liu, linux-btrfs; +Cc: dsterba, clm, linux-kernel
在 2026/3/28 17:10, Teng Liu 写道:
> 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.
>
> Signed-off-by: Teng Liu <27rabbitlt@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
And pushed to for-next.
> ---
> Changes in v2:
> - Use btrfs_err() instead of btrfs_debug() (Qu Wenruo)
> - Use PTR_ERR(inode) instead of hardcoded -EIO (Qu Wenruo)
> - Include error code in the log message (Qu Wenruo)
>
> fs/btrfs/block-group.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index ebf507909..89bfc9db0 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -3343,7 +3343,13 @@ static int 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)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-28 7:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-28 6:40 [PATCH v2] btrfs: replace BUG_ON() with error return in cache_save_setup() Teng Liu
2026-03-28 7:13 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox