Current set_btree_ioerr() only accepts @page parameter and grabs extent
buffer from page::private.

This works fine for sector size == PAGE_SIZE case, but not for subpage
case.

Adds an extra parameter, @eb, for callers to pass extent buffer to this
function, so that subpage code can reuse this function.

And also add subpage special handling to update
btrfs_subpage::error_bitmap.

Signed-off-by: Qu Wenruo <w...@suse.com>
---
 fs/btrfs/extent_io.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 2d16d92107bc..b6fbb512abfd 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3982,12 +3982,11 @@ static noinline_for_stack int 
lock_extent_buffer_for_io(struct extent_buffer *eb
        return ret;
 }
 
-static void set_btree_ioerr(struct page *page)
+static void set_btree_ioerr(struct page *page, struct extent_buffer *eb)
 {
-       struct extent_buffer *eb = (struct extent_buffer *)page->private;
-       struct btrfs_fs_info *fs_info;
+       struct btrfs_fs_info *fs_info = eb->fs_info;
 
-       SetPageError(page);
+       btrfs_page_set_error(fs_info, page, eb->start, eb->len);
        if (test_and_set_bit(EXTENT_BUFFER_WRITE_ERR, &eb->bflags))
                return;
 
@@ -3995,7 +3994,6 @@ static void set_btree_ioerr(struct page *page)
         * If we error out, we should add back the dirty_metadata_bytes
         * to make it consistent.
         */
-       fs_info = eb->fs_info;
        percpu_counter_add_batch(&fs_info->dirty_metadata_bytes,
                                 eb->len, fs_info->dirty_metadata_batch);
 
@@ -4039,13 +4037,13 @@ static void set_btree_ioerr(struct page *page)
         */
        switch (eb->log_index) {
        case -1:
-               set_bit(BTRFS_FS_BTREE_ERR, &eb->fs_info->flags);
+               set_bit(BTRFS_FS_BTREE_ERR, &fs_info->flags);
                break;
        case 0:
-               set_bit(BTRFS_FS_LOG1_ERR, &eb->fs_info->flags);
+               set_bit(BTRFS_FS_LOG1_ERR, &fs_info->flags);
                break;
        case 1:
-               set_bit(BTRFS_FS_LOG2_ERR, &eb->fs_info->flags);
+               set_bit(BTRFS_FS_LOG2_ERR, &fs_info->flags);
                break;
        default:
                BUG(); /* unexpected, logic error */
@@ -4070,7 +4068,7 @@ static void end_bio_extent_buffer_writepage(struct bio 
*bio)
                if (bio->bi_status ||
                    test_bit(EXTENT_BUFFER_WRITE_ERR, &eb->bflags)) {
                        ClearPageUptodate(page);
-                       set_btree_ioerr(page);
+                       set_btree_ioerr(page, eb);
                }
 
                end_page_writeback(page);
@@ -4126,7 +4124,7 @@ static noinline_for_stack int write_one_eb(struct 
extent_buffer *eb,
                                         end_bio_extent_buffer_writepage,
                                         0, 0, 0, false);
                if (ret) {
-                       set_btree_ioerr(p);
+                       set_btree_ioerr(p, eb);
                        if (PageWriteback(p))
                                end_page_writeback(p);
                        if (atomic_sub_and_test(num_pages - i, &eb->io_pages))
-- 
2.30.1

Reply via email to