btrfs: simplify the error handling in __extent_writepage_io
authorChristoph Hellwig <hch@lst.de>
Mon, 27 Feb 2023 15:17:02 +0000 (08:17 -0700)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Apr 2023 16:01:16 +0000 (18:01 +0200)
Remove the has_error and saved_ret variables, and just jump to a goto
label for error handling from the only place returning an error from the
main loop.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c

index 70f6712..3d11298 100644 (file)
@@ -1502,10 +1502,8 @@ 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;
-       bool has_error = false;
        bool compressed;
 
        ret = btrfs_writepage_cow_fixup(page);
@@ -1556,10 +1554,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
                if (IS_ERR(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;
+                       goto out_error;
                }
 
                extent_offset = cur - em->start;
@@ -1613,18 +1608,19 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
 
                submit_extent_page(bio_ctrl, disk_bytenr, page, iosize,
                                   cur - page_offset(page));
-               ret = 0;
                cur += iosize;
                nr++;
        }
+
+       btrfs_page_assert_not_dirty(fs_info, page);
+       *nr_ret = nr;
+       return 0;
+
+out_error:
        /*
         * If we finish without problem, we should not only clear page dirty,
         * but also empty subpage dirty bits
         */
-       if (!has_error)
-               btrfs_page_assert_not_dirty(fs_info, page);
-       else
-               ret = saved_ret;
        *nr_ret = nr;
        return ret;
 }