btrfs: return correct error number for __extent_writepage_io()
authorQu Wenruo <wqu@suse.com>
Tue, 12 Apr 2022 12:30:15 +0000 (20:30 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 16 May 2022 15:03:13 +0000 (17:03 +0200)
commit44e5801fada6925d2bba1987c7b59cbcc9d0d592
tree5205e31dda5464686fb1fc7b81f0396acf143458
parent10f7f6f879c28f8368d6516ab1ccf3517a1f5d3d
btrfs: return correct error number for __extent_writepage_io()

[BUG]
If we hit an error from submit_extent_page() inside
__extent_writepage_io(), we could still return 0 to the caller, and
even trigger the warning in btrfs_page_assert_not_dirty().

[CAUSE]
In __extent_writepage_io(), if we hit an error from
submit_extent_page(), we will just clean up the range and continue.

This is completely fine for regular PAGE_SIZE == sectorsize, as we can
only hit one sector in one page, thus after the error we're ensured to
exit and @ret will be saved.

But for subpage case, we may have other dirty subpage range in the page,
and in the next loop, we may succeeded submitting the next range.

In that case, @ret will be overwritten, and we return 0 to the caller,
while we have hit some error.

[FIX]
Introduce @has_error and @saved_ret to record the first error we hit, so
we will never forget what error we hit.

CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c