Skip to content

Commit 2b952ee

Browse files
adam900710kdave
authored andcommitted
btrfs: extent_io: Handle errors better in btree_write_cache_pages()
In btree_write_cache_pages(), 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 3065976 commit 2b952ee

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
@@ -3748,7 +3748,6 @@ int btree_write_cache_pages(struct address_space *mapping,
37483748
.sync_io = wbc->sync_mode == WB_SYNC_ALL,
37493749
};
37503750
int ret = 0;
3751-
int flush_ret;
37523751
int done = 0;
37533752
int nr_to_write_done = 0;
37543753
struct pagevec pvec;
@@ -3848,8 +3847,12 @@ int btree_write_cache_pages(struct address_space *mapping,
38483847
index = 0;
38493848
goto retry;
38503849
}
3851-
flush_ret = flush_write_bio(&epd);
3852-
BUG_ON(flush_ret < 0);
3850+
ASSERT(ret <= 0);
3851+
if (ret < 0) {
3852+
end_write_bio(&epd, ret);
3853+
return ret;
3854+
}
3855+
ret = flush_write_bio(&epd);
38533856
return ret;
38543857
}
38553858

0 commit comments

Comments
 (0)