Skip to content

Commit 4bd427f

Browse files
adam900710kdave
authored andcommitted
btrfs: concentrate the error handling of submit_one_sector()
Currently submit_one_sector() has only one failure path from btrfs_get_extent(). However the error handling is split into two parts, one inside submit_one_sector(), which clears the dirty flag and finishes the writeback for the fs block. The other part is to submit any remaining bio inside bio_ctrl and mark the ordered extent finished for the fs block. There is no special reason that we must split the error handling, let's just concentrate all the error handling into submit_one_sector(). Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent d9ba850 commit 4bd427f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

fs/btrfs/extent_io.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode,
16111611

16121612
/*
16131613
* Return 0 if we have submitted or queued the sector for submission.
1614-
* Return <0 for critical errors, and the sector will have its dirty flag cleared.
1614+
* Return <0 for critical errors, and the involved sector will be cleaned up.
16151615
*
16161616
* Caller should make sure filepos < i_size and handle filepos >= i_size case.
16171617
*/
@@ -1635,6 +1635,13 @@ static int submit_one_sector(struct btrfs_inode *inode,
16351635

16361636
em = btrfs_get_extent(inode, NULL, filepos, sectorsize);
16371637
if (IS_ERR(em)) {
1638+
/*
1639+
* bio_ctrl may contain a bio crossing several folios.
1640+
* Submit it immediately so that the bio has a chance
1641+
* to finish normally, other than marked as error.
1642+
*/
1643+
submit_one_bio(bio_ctrl);
1644+
16381645
/*
16391646
* When submission failed, we should still clear the folio dirty.
16401647
* Or the folio will be written back again but without any
@@ -1643,6 +1650,13 @@ static int submit_one_sector(struct btrfs_inode *inode,
16431650
btrfs_folio_clear_dirty(fs_info, folio, filepos, sectorsize);
16441651
btrfs_folio_set_writeback(fs_info, folio, filepos, sectorsize);
16451652
btrfs_folio_clear_writeback(fs_info, folio, filepos, sectorsize);
1653+
1654+
/*
1655+
* Since there is no bio submitted to finish the ordered
1656+
* extent, we have to manually finish this sector.
1657+
*/
1658+
btrfs_mark_ordered_io_finished(inode, folio, filepos,
1659+
fs_info->sectorsize, false);
16461660
return PTR_ERR(em);
16471661
}
16481662

@@ -1769,19 +1783,6 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
17691783
}
17701784
ret = submit_one_sector(inode, folio, cur, bio_ctrl, i_size);
17711785
if (unlikely(ret < 0)) {
1772-
/*
1773-
* bio_ctrl may contain a bio crossing several folios.
1774-
* Submit it immediately so that the bio has a chance
1775-
* to finish normally, other than marked as error.
1776-
*/
1777-
submit_one_bio(bio_ctrl);
1778-
/*
1779-
* Failed to grab the extent map which should be very rare.
1780-
* Since there is no bio submitted to finish the ordered
1781-
* extent, we have to manually finish this sector.
1782-
*/
1783-
btrfs_mark_ordered_io_finished(inode, folio, cur,
1784-
fs_info->sectorsize, false);
17851786
if (!found_error)
17861787
found_error = ret;
17871788
continue;

0 commit comments

Comments
 (0)