btrfs: replace BUG_ON() with error return in cache_save_setup()
PATCH v2 1/1 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.
---
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(-)
fs/btrfs/block-group.c +7 -1
@@ -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)
Signature · 1 line
2.53.0
Quoted 11 lines · Teng Liu
In
cache_save_setup(), ifcreate_free_space_inode()succeeds but the subsequentlookup_free_space_inode()still fails on retry, theBUG_ON(retries)will crash the kernel. This can happen due to I/O errors or transient failures, not just programming bugs.Replace the
BUG_ONwith proper error handling that returns the original error code through the existing cleanup path. The callers already handle this gracefully:disk_cache_statedefaults toBTRFS_DC_ERROR, so the space cache simply won't be written for that block group.Signed-off-by Teng Liu <[email protected]>
And pushed to for-next.
Quoted 28 lines
---
Changes in v2:
- Usebtrfs_err()instead ofbtrfs_debug()(Qu Wenruo)
- UsePTR_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(-)fs/btrfs/block-group.c +7
-1@@ -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)