All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: record writeback error when discarding pages on failed delalloc
@ 2026-10-16 10:16 guolingxing
  2026-10-16 10:38 ` sashiko-bot
  2026-10-16 11:03 ` [PATCH v2] " guolingxing
  0 siblings, 2 replies; 4+ messages in thread
From: guolingxing @ 2026-10-16 10:16 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger, Aneesh Kumar K . V
  Cc: Baokun Li, Jan Kara, Ojaswin Mujoo, Ritesh Harjani, Zhang Yi,
	linux-ext4, linux-kernel, guolingxing, stable

When mpage_map_and_submit_extent() gives up on a failed block mapping,
it sets give_up_on_write so that mpage_release_unused_pages() discards
the remaining dirty folios. However, the error is not recorded in the
mapping's writeback error state.

If this happens during background writeback, a later fsync() may
report success even though the dirty data was discarded and never
written. Returning the error from ext4_writepages() is not sufficient
to notify a later fsync(). In addition, ext4_do_writepages() may clear
-ENOSPC when committing the journal and retrying, even after the
affected dirty folios have been discarded.

Call mapping_set_error() when deciding to give up on the write,
before the dirty folios are invalidated, so that fsync() can report
the writeback failure through the mapping's error state.

Fixes: c4a0c46ec92c ("ext4: invalidate pages if delalloc block allocation fails.")
Cc: stable@vger.kernel.org
Signed-off-by: guolingxing <guolingxing@tju.edu.cn>
---
 fs/ext4/inode.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 26f0f9714f03..dba903d188e2 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2505,6 +2505,12 @@ static int mpage_map_and_submit_extent(handle_t *handle,
 				ext4_print_free_blocks(inode);
 		invalidate_dirty_pages:
 			*give_up_on_write = true;
+			/*
+			 * Record the error so that a subsequent fsync()
+			 * / errseq check can observe the data loss that
+			 * discarding these dirty pages implies.
+			 */
+			mapping_set_error(inode->i_mapping, err);
 			return err;
 		}
 		progress = 1;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-16 11:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-16 10:16 [PATCH] ext4: record writeback error when discarding pages on failed delalloc guolingxing
2026-10-16 10:38 ` sashiko-bot
2026-10-16 11:03 ` [PATCH v2] " guolingxing
2026-10-16 11:15   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.