diff options
author | Zhang Yi <yi.zhang@huawei.com> | 2025-04-23 16:52:56 +0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2025-05-15 13:14:51 -0400 |
commit | 1b4d2a0b794669e54914e3f429c08e49ea40b40c (patch) | |
tree | 7958556b3bd19eb75bce361eb26734dcae9aedd2 /fs/ext4/inode.c | |
parent | 7871da20d484d5c7e536bfd52845b6be4488ff30 (diff) |
ext4: check env when mapping and modifying extents
Add ext4_check_map_extents_env() to the places where loading extents,
mapping blocks, removing blocks, and modifying extents, excluding the
I/O writeback context. This function will verify whether the locking
mechanisms in place are adequate.
Suggested-by: Jan Kara <jack@suse.cz>
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Link: https://patch.msgid.link/20250423085257.122685-9-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5b591a47ff84..9b0bfbbdb50b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -650,11 +650,14 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, return -EFSCORRUPTED; /* - * Do not allow caching of unrelated ranges of extents during I/O - * submission. + * Callers from the context of data submission are the only exceptions + * for regular files that do not hold the i_rwsem or invalidate_lock. + * However, caching unrelated ranges is not permitted. */ if (flags & EXT4_GET_BLOCKS_IO_SUBMIT) WARN_ON_ONCE(!(flags & EXT4_EX_NOCACHE)); + else + ext4_check_map_extents_env(inode); /* Lookup extent status tree firstly */ if (!(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) && @@ -1801,6 +1804,8 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map) ext_debug(inode, "max_blocks %u, logical block %lu\n", map->m_len, (unsigned long) map->m_lblk); + ext4_check_map_extents_env(inode); + /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { map->m_len = min_t(unsigned int, map->m_len, @@ -4113,6 +4118,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) ext4_lblk_t hole_len = end_lblk - start_lblk; ext4_fc_track_inode(handle, inode); + ext4_check_map_extents_env(inode); down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode); @@ -4266,8 +4272,9 @@ int ext4_truncate(struct inode *inode) goto out_stop; ext4_fc_track_inode(handle, inode); - down_write(&EXT4_I(inode)->i_data_sem); + ext4_check_map_extents_env(inode); + down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode); if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) |