Skip to content

Commit ee15967

Browse files
adam900710kdave
authored andcommitted
btrfs: integrate the error handling of submit_one_sector()
Currently submit_one_sector() has only one failure pattern 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> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent c7459b0 commit ee15967

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
@@ -1598,7 +1598,7 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode,
15981598

15991599
/*
16001600
* Return 0 if we have submitted or queued the sector for submission.
1601-
* Return <0 for critical errors, and the sector will have its dirty flag cleared.
1601+
* Return <0 for critical errors, and the involved sector will be cleaned up.
16021602
*
16031603
* Caller should make sure filepos < i_size and handle filepos >= i_size case.
16041604
*/
@@ -1622,6 +1622,13 @@ static int submit_one_sector(struct btrfs_inode *inode,
16221622

16231623
em = btrfs_get_extent(inode, NULL, filepos, sectorsize);
16241624
if (IS_ERR(em)) {
1625+
/*
1626+
* bio_ctrl may contain a bio crossing several folios.
1627+
* Submit it immediately so that the bio has a chance
1628+
* to finish normally, other than marked as error.
1629+
*/
1630+
submit_one_bio(bio_ctrl);
1631+
16251632
/*
16261633
* When submission failed, we should still clear the folio dirty.
16271634
* Or the folio will be written back again but without any
@@ -1630,6 +1637,13 @@ static int submit_one_sector(struct btrfs_inode *inode,
16301637
btrfs_folio_clear_dirty(fs_info, folio, filepos, sectorsize);
16311638
btrfs_folio_set_writeback(fs_info, folio, filepos, sectorsize);
16321639
btrfs_folio_clear_writeback(fs_info, folio, filepos, sectorsize);
1640+
1641+
/*
1642+
* Since there is no bio submitted to finish the ordered
1643+
* extent, we have to manually finish this sector.
1644+
*/
1645+
btrfs_mark_ordered_io_finished(inode, folio, filepos,
1646+
fs_info->sectorsize, false);
16331647
return PTR_ERR(em);
16341648
}
16351649

@@ -1739,19 +1753,6 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
17391753
}
17401754
ret = submit_one_sector(inode, folio, cur, bio_ctrl, i_size);
17411755
if (unlikely(ret < 0)) {
1742-
/*
1743-
* bio_ctrl may contain a bio crossing several folios.
1744-
* Submit it immediately so that the bio has a chance
1745-
* to finish normally, other than marked as error.
1746-
*/
1747-
submit_one_bio(bio_ctrl);
1748-
/*
1749-
* Failed to grab the extent map which should be very rare.
1750-
* Since there is no bio submitted to finish the ordered
1751-
* extent, we have to manually finish this sector.
1752-
*/
1753-
btrfs_mark_ordered_io_finished(inode, folio, cur,
1754-
fs_info->sectorsize, false);
17551756
if (!found_error)
17561757
found_error = ret;
17571758
continue;

0 commit comments

Comments
 (0)