
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IB5WC2 -------------------------------- ext4 sometimes fails on generic/269 and generic/270 in buffered_iomap mode. These tests run fsstress and ENOSPC hitters in parallel. If the fsstress process is killed when a direct write fails due to ENOSPC, it may interrupt zero_range, as follows: ext4_dio_write_iter ext4_orphan_add(inode) iomap_dio_rw return -ENOSPC; ext4_inode_extension_cleanup ext4_truncate_failed_write(inode) ext4_truncate(inode) ext4_block_truncate_page(mapping, inode->i_size) ext4_block_zero_page_range ext4_iomap_zero_range iomap_zero_range iomap_zero_iter iomap_write_begin if (fatal_signal_pending(current)) return -EINTR; ext4_orphan_del(NULL, inode) Then, the inode was removed from the orphan list without running ext4_ext_truncate(), which corrupted the file system. A later fsck found the file system inconsistent, causing the test case to fail. Since zero range operations typically involve small amounts of data and are frequently used to prevent the exposure of stale data, we avoid interrupting IOMAP_ZERO by signals within iomap_write_begin(). Fixes: a85e54b5fdda ("ext4: partial zero eof block on unaligned inode size extension") Signed-off-by: Baokun Li <libaokun1@huawei.com> --- fs/iomap/buffered-io.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 0c06e97d08de..c994b2f058c3 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -844,7 +844,12 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, if (srcmap != &iter->iomap) BUG_ON(pos + len > srcmap->offset + srcmap->length); - if (fatal_signal_pending(current)) + /* + * Zero range operations typically involve small amounts of data + * and are frequently used to prevent the exposure of stale data. + * Therefore, do not interrupt it here. + */ + if (iter->flags != IOMAP_ZERO && fatal_signal_pending(current)) return -EINTR; if (!mapping_large_folio_support(iter->inode->i_mapping)) -- 2.46.1