Skip to content

Commit bbc9a6e

Browse files
adam900710kdave
authored andcommitted
btrfs: replace BUG_ON() in btrfs_csum_one_bio() with proper error handling
There is a BUG_ON() in btrfs_csum_one_bio() to catch code logic error. It has indeed caught several bugs during subpage development. But the BUG_ON() itself will bring down the whole system which is an overkill. Replace it with a WARN() and exit gracefully, so that it won't crash the whole system while we can still catch the code logic error. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f79645d commit bbc9a6e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

fs/btrfs/file-item.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,18 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
665665

666666
if (!ordered) {
667667
ordered = btrfs_lookup_ordered_extent(inode, offset);
668-
BUG_ON(!ordered); /* Logic error */
668+
/*
669+
* The bio range is not covered by any ordered extent,
670+
* must be a code logic error.
671+
*/
672+
if (unlikely(!ordered)) {
673+
WARN(1, KERN_WARNING
674+
"no ordered extent for root %llu ino %llu offset %llu\n",
675+
inode->root->root_key.objectid,
676+
btrfs_ino(inode), offset);
677+
kvfree(sums);
678+
return BLK_STS_IOERR;
679+
}
669680
}
670681

671682
nr_sectors = BTRFS_BYTES_TO_BLKS(fs_info,

0 commit comments

Comments
 (0)