From 07d62890ef19e41a87735b8fe1ec65922b5ecd8c Mon Sep 17 00:00:00 2001 From: Baokun Li Date: Mon, 29 Jun 2026 19:38:22 +0800 Subject: [PATCH] ext4: prevent sleeping allocation in NOWAIT write path Block allocation requires journal access which may sleep, violating NOWAIT semantics. Return -EAGAIN early when IOMAP_NOWAIT is set, allowing the caller to retry without the NOWAIT constraint. This ensures that write paths using IOMAP_NOWAIT (e.g., DIO with RWF_NOWAIT) will not block on journal operations when blocks need to be allocated. Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260611163441.2431805-1-libaokun@linux.alibaba.com?part=1 Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Signed-off-by: Baokun Li Link: https://patch.msgid.link/20260629113827.4074335-2-libaokun@linux.alibaba.com Signed-off-by: Theodore Ts'o --- fs/ext4/inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 72a334978f69..fd86d536ff27 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3687,6 +3687,9 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map, int ret, dio_credits, m_flags = 0, retries = 0; bool force_commit = false; + if (flags & IOMAP_NOWAIT) + return -EAGAIN; + /* * Trim the mapping request to the maximum value that we can map at * once for direct I/O.