Skip to content

Commit f434062

Browse files
adam900710kdave
authored andcommitted
btrfs: extent_io: Move the BUG_ON() in flush_write_bio() one level up
We have a BUG_ON() in flush_write_bio() to handle the return value of submit_one_bio(). Move the BUG_ON() one level up to all its callers. This patch will introduce temporary variable, @flush_ret to keep code change minimal in this patch. That variable will be cleaned up when enhancing the error handling later. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 6348905 commit f434062

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

fs/btrfs/extent_io.c

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,28 @@ static int __must_check submit_one_bio(struct bio *bio, int mirror_num,
170170
return blk_status_to_errno(ret);
171171
}
172172

173-
static void flush_write_bio(struct extent_page_data *epd)
173+
/*
174+
* Submit bio from extent page data via submit_one_bio
175+
*
176+
* Return 0 if everything is OK.
177+
* Return <0 for error.
178+
*/
179+
static int __must_check flush_write_bio(struct extent_page_data *epd)
174180
{
175-
if (epd->bio) {
176-
int ret;
181+
int ret = 0;
177182

183+
if (epd->bio) {
178184
ret = submit_one_bio(epd->bio, 0, 0);
179-
BUG_ON(ret < 0); /* -ENOMEM */
185+
/*
186+
* Clean up of epd->bio is handled by its endio function.
187+
* And endio is either triggered by successful bio execution
188+
* or the error handler of submit bio hook.
189+
* So at this point, no matter what happened, we don't need
190+
* to clean up epd->bio.
191+
*/
180192
epd->bio = NULL;
181193
}
194+
return ret;
182195
}
183196

184197
int __init extent_io_init(void)
@@ -3476,7 +3489,8 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,
34763489

34773490
if (!btrfs_try_tree_write_lock(eb)) {
34783491
flush = 1;
3479-
flush_write_bio(epd);
3492+
ret = flush_write_bio(epd);
3493+
BUG_ON(ret < 0);
34803494
btrfs_tree_lock(eb);
34813495
}
34823496

@@ -3485,7 +3499,8 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,
34853499
if (!epd->sync_io)
34863500
return 0;
34873501
if (!flush) {
3488-
flush_write_bio(epd);
3502+
ret = flush_write_bio(epd);
3503+
BUG_ON(ret < 0);
34893504
flush = 1;
34903505
}
34913506
while (1) {
@@ -3526,7 +3541,8 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,
35263541

35273542
if (!trylock_page(p)) {
35283543
if (!flush) {
3529-
flush_write_bio(epd);
3544+
ret = flush_write_bio(epd);
3545+
BUG_ON(ret < 0);
35303546
flush = 1;
35313547
}
35323548
lock_page(p);
@@ -3718,6 +3734,7 @@ int btree_write_cache_pages(struct address_space *mapping,
37183734
.sync_io = wbc->sync_mode == WB_SYNC_ALL,
37193735
};
37203736
int ret = 0;
3737+
int flush_ret;
37213738
int done = 0;
37223739
int nr_to_write_done = 0;
37233740
struct pagevec pvec;
@@ -3817,7 +3834,8 @@ int btree_write_cache_pages(struct address_space *mapping,
38173834
index = 0;
38183835
goto retry;
38193836
}
3820-
flush_write_bio(&epd);
3837+
flush_ret = flush_write_bio(&epd);
3838+
BUG_ON(flush_ret < 0);
38213839
return ret;
38223840
}
38233841

@@ -3914,7 +3932,8 @@ static int extent_write_cache_pages(struct address_space *mapping,
39143932
* tmpfs file mapping
39153933
*/
39163934
if (!trylock_page(page)) {
3917-
flush_write_bio(epd);
3935+
ret = flush_write_bio(epd);
3936+
BUG_ON(ret < 0);
39183937
lock_page(page);
39193938
}
39203939

@@ -3924,8 +3943,10 @@ static int extent_write_cache_pages(struct address_space *mapping,
39243943
}
39253944

39263945
if (wbc->sync_mode != WB_SYNC_NONE) {
3927-
if (PageWriteback(page))
3928-
flush_write_bio(epd);
3946+
if (PageWriteback(page)) {
3947+
ret = flush_write_bio(epd);
3948+
BUG_ON(ret < 0);
3949+
}
39293950
wait_on_page_writeback(page);
39303951
}
39313952

@@ -3986,6 +4007,7 @@ static int extent_write_cache_pages(struct address_space *mapping,
39864007
int extent_write_full_page(struct page *page, struct writeback_control *wbc)
39874008
{
39884009
int ret;
4010+
int flush_ret;
39894011
struct extent_page_data epd = {
39904012
.bio = NULL,
39914013
.tree = &BTRFS_I(page->mapping->host)->io_tree,
@@ -3995,14 +4017,16 @@ int extent_write_full_page(struct page *page, struct writeback_control *wbc)
39954017

39964018
ret = __extent_writepage(page, wbc, &epd);
39974019

3998-
flush_write_bio(&epd);
4020+
flush_ret = flush_write_bio(&epd);
4021+
BUG_ON(flush_ret < 0);
39994022
return ret;
40004023
}
40014024

40024025
int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
40034026
int mode)
40044027
{
40054028
int ret = 0;
4029+
int flush_ret;
40064030
struct address_space *mapping = inode->i_mapping;
40074031
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
40084032
struct page *page;
@@ -4035,14 +4059,16 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
40354059
start += PAGE_SIZE;
40364060
}
40374061

4038-
flush_write_bio(&epd);
4062+
flush_ret = flush_write_bio(&epd);
4063+
BUG_ON(flush_ret < 0);
40394064
return ret;
40404065
}
40414066

40424067
int extent_writepages(struct address_space *mapping,
40434068
struct writeback_control *wbc)
40444069
{
40454070
int ret = 0;
4071+
int flush_ret;
40464072
struct extent_page_data epd = {
40474073
.bio = NULL,
40484074
.tree = &BTRFS_I(mapping->host)->io_tree,
@@ -4051,7 +4077,8 @@ int extent_writepages(struct address_space *mapping,
40514077
};
40524078

40534079
ret = extent_write_cache_pages(mapping, wbc, &epd);
4054-
flush_write_bio(&epd);
4080+
flush_ret = flush_write_bio(&epd);
4081+
BUG_ON(flush_ret < 0);
40554082
return ret;
40564083
}
40574084

0 commit comments

Comments
 (0)