Skip to contentSkip to conversation

btrfs: return any hit error from extent_writepage_io()

PATCH In review Qu Wenruo 2 participants 2 messages Sep 17, 2025 – Sep 18, 2025 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: return any hit error from extent_writepage_io()

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 8bf334beb349 ("btrfs: fix double accounting race when extent_writepage_io() failed")
---
 fs/btrfs/extent_io.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +5 -4
index 258658856195..5daeb596e99b 100644
@@ -1682,7 +1682,7 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
 	struct btrfs_fs_info *fs_info = inode->root->fs_info;
 	unsigned long range_bitmap = 0;
 	bool submitted_io = false;
-	bool error = false;
+	int found_error = 0;
 	const u64 folio_start = folio_pos(folio);
 	const unsigned int blocks_per_folio = btrfs_blocks_per_folio(fs_info, folio);
 	u64 cur;
@@ -1746,7 +1746,8 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
 			 */
 			btrfs_mark_ordered_io_finished(inode, folio, cur,
 						       fs_info->sectorsize, false);
-			error = true;
+			if (!found_error)
+				found_error = ret;
 			continue;
 		}
 		submitted_io = true;
@@ -1763,11 +1764,11 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
 	 * If we hit any error, the corresponding sector will have its dirty
 	 * flag cleared and writeback finished, thus no need to handle the error case.
 	 */
-	if (!submitted_io && !error) {
+	if (!submitted_io && !found_error) {
 		btrfs_folio_set_writeback(fs_info, folio, start, len);
 		btrfs_folio_clear_writeback(fs_info, folio, start, len);
 	}
-	return ret;
+	return found_error;
 }
 
 /*
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Qu Wenruo

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.

Quoted 7 lines

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 8bf334beb349 ("btrfs: fix double accounting race when extent_writepage_io() failed")

LGTM.

Quoted 45 lines
---
 fs/btrfs/extent_io.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +5 -5
index 258658856195..5daeb596e99b 100644
@@ -1682,7 +1682,7 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
        struct btrfs_fs_info *fs_info = inode->root->fs_info;
        unsigned long range_bitmap = 0;
        bool submitted_io = false;
-       bool error = false;
+       int found_error = 0;
        const u64 folio_start = folio_pos(folio);
        const unsigned int blocks_per_folio = btrfs_blocks_per_folio(fs_info, folio);
        u64 cur;
@@ -1746,7 +1746,8 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
                         */
                        btrfs_mark_ordered_io_finished(inode, folio, cur,
                                                       fs_info->sectorsize, false);
-                       error = true;
+                       if (!found_error)
+                               found_error = ret;
                        continue;
                }
                submitted_io = true;
@@ -1763,11 +1764,11 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
         * If we hit any error, the corresponding sector will have its dirty
         * flag cleared and writeback finished, thus no need to handle the error case.
         */
-       if (!submitted_io && !error) {
+       if (!submitted_io && !found_error) {
                btrfs_folio_set_writeback(fs_info, folio, start, len);
                btrfs_folio_clear_writeback(fs_info, folio, start, len);
        }
-       return ret;
+       return found_error;
 }
 
 /*
--

2.50.1