Skip to content

Commit 01e852a

Browse files
adam900710gregkh
authored andcommitted
btrfs: return any hit error from extent_writepage_io()
[ Upstream commit 2d83ed6 ] Since the support of bs < ps support, extent_writepage_io() will submit multiple blocks inside the folio. But if we hit error submitting one sector, but the next sector can still be submitted successfully, the function extent_writepage_io() will still return 0. This will make btrfs to silently ignore the error without setting error flag for the filemap. Fix it by recording the first error hit, and always return that value. Fixes: 8bf334b ("btrfs: fix double accounting race when extent_writepage_io() failed") Reviewed-by: Daniel Vacek <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 44cd990 commit 01e852a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

fs/btrfs/extent_io.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
16211621
struct btrfs_fs_info *fs_info = inode->root->fs_info;
16221622
unsigned long range_bitmap = 0;
16231623
bool submitted_io = false;
1624-
bool error = false;
1624+
int found_error = 0;
16251625
const u64 folio_start = folio_pos(folio);
16261626
const unsigned int blocks_per_folio = btrfs_blocks_per_folio(fs_info, folio);
16271627
u64 cur;
@@ -1685,7 +1685,8 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
16851685
*/
16861686
btrfs_mark_ordered_io_finished(inode, folio, cur,
16871687
fs_info->sectorsize, false);
1688-
error = true;
1688+
if (!found_error)
1689+
found_error = ret;
16891690
continue;
16901691
}
16911692
submitted_io = true;
@@ -1702,11 +1703,11 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
17021703
* If we hit any error, the corresponding sector will have its dirty
17031704
* flag cleared and writeback finished, thus no need to handle the error case.
17041705
*/
1705-
if (!submitted_io && !error) {
1706+
if (!submitted_io && !found_error) {
17061707
btrfs_folio_set_writeback(fs_info, folio, start, len);
17071708
btrfs_folio_clear_writeback(fs_info, folio, start, len);
17081709
}
1709-
return ret;
1710+
return found_error;
17101711
}
17111712

17121713
/*

0 commit comments

Comments
 (0)