Skip to content

Commit 02c6db4

Browse files
adam900710kdave
authored andcommitted
btrfs: extent_io: Handle errors better in extent_write_locked_range()
We can only get @ret <= 0. Add an ASSERT() for it just in case. Then, instead of submitting the write bio even we got some error, check the return value first. If we have already hit some error, just clean up the corrupted or half-baked bio, and return error. If there is no error so far, then call flush_write_bio() and return the result. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e06808b commit 02c6db4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fs/btrfs/extent_io.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4042,7 +4042,6 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
40424042
int mode)
40434043
{
40444044
int ret = 0;
4045-
int flush_ret;
40464045
struct address_space *mapping = inode->i_mapping;
40474046
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
40484047
struct page *page;
@@ -4075,8 +4074,12 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
40754074
start += PAGE_SIZE;
40764075
}
40774076

4078-
flush_ret = flush_write_bio(&epd);
4079-
BUG_ON(flush_ret < 0);
4077+
ASSERT(ret <= 0);
4078+
if (ret < 0) {
4079+
end_write_bio(&epd, ret);
4080+
return ret;
4081+
}
4082+
ret = flush_write_bio(&epd);
40804083
return ret;
40814084
}
40824085

0 commit comments

Comments
 (0)