]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
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)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 10 Aug 2022 07:23:35 +0000 (09:23 +0200)
BugLink: https://bugs.launchpad.net/bugs/1981864
commit 44e5801fada6925d2bba1987c7b59cbcc9d0d592 upstream.

[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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
fs/btrfs/extent_io.c

index 96aeb16bd65c97ec6c0ab50119a6e4ddc4a6dc65..3895fce3674ee91aebc8edc3786f6cbcd77924a4 100644 (file)
@@ -3902,10 +3902,12 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
        u64 extent_offset;
        u64 block_start;
        struct extent_map *em;
+       int saved_ret = 0;
        int ret = 0;
        int nr = 0;
        u32 opf = REQ_OP_WRITE;
        const unsigned int write_flags = wbc_to_write_flags(wbc);
+       bool has_error = false;
        bool compressed;
 
        ret = btrfs_writepage_cow_fixup(page);
@@ -3956,6 +3958,9 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
                if (IS_ERR_OR_NULL(em)) {
                        btrfs_page_set_error(fs_info, page, cur, end - cur + 1);
                        ret = PTR_ERR_OR_ZERO(em);
+                       has_error = true;
+                       if (!saved_ret)
+                               saved_ret = ret;
                        break;
                }
 
@@ -4019,6 +4024,10 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
                                         end_bio_extent_writepage,
                                         0, 0, false);
                if (ret) {
+                       has_error = true;
+                       if (!saved_ret)
+                               saved_ret = ret;
+
                        btrfs_page_set_error(fs_info, page, cur, iosize);
                        if (PageWriteback(page))
                                btrfs_page_clear_writeback(fs_info, page, cur,
@@ -4032,8 +4041,10 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
         * If we finish without problem, we should not only clear page dirty,
         * but also empty subpage dirty bits
         */
-       if (!ret)
+       if (!has_error)
                btrfs_page_assert_not_dirty(fs_info, page);
+       else
+               ret = saved_ret;
        *nr_ret = nr;
        return ret;
 }