linux/fs/ext4
Zhang Yi 14a210c110 ext4: trim delalloc extent
In ext4_da_map_blocks(), we could find four kind of extents in the
extent status tree: hole, unwritten, written and delayed extent. Now we
only trim the map len if we found an unwritten extent or a written
extent. This is okay now since map->m_len is always set to one and we
always insert one delayed block at a time. But this will become isn't
okay for other two cases if ext4_insert_delayed_block() and
ext4_da_map_blocks() support inserting multiple map->len blocks later.

1. If we found a hole in the extent status tree which es->es_len is
   shorter than the length we want to write, we should trim the
   map->m_len to prevent adding extra delay more blocks than we
   expected. For example, assume we write data [A, C) to a file that
   contains a hole extent [A, B) and a written extent [B, D) in the
   cache.

                         A     B  C  D
   before da write:   ...hhhhhh|wwwwww....

   Then we will get extent [A, B), we should trim map->m_len to B-A
   before inserting new delalloc blocks, if not, the range [B, C) will
   be duplicated.

2. If we found a delayed extent in the extent status tree which
   es->es_len is shorter than the length we want to write, we should
   trim the map->m_len to es->es_len and return directly since the front
   part of this map has been delayed, we can't insert the delalloc
   extent that contains the latter part in this round, we should return
   the delayed length and the caller should increase the position and
   call ext4_da_map_blocks() again. For example, assume we write data
   [A, C) to a file that contains a delayed extent [A, B) in the cache.

                         A     B  C
   before da write:   ...dddddd|hhh....

   Then we will get delayed extent [A, B), we should also trim map->m_len
   to B-A and return, if not, we will incorrectly assume that the write
   is complete and won't insert [B, C).

So we need to always trim the map->m_len if the found es->es_len in the
extent status tree is shorter than the map->m_len, prearing for
inserting a extent with multiple delalloc blocks. This patch only does a
pre-fix, the handle is crude and ext4_da_map_blocks() deserve a cleanup,
we will do that later.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20240517124005.347221-5-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2024-06-27 18:04:49 -04:00
..
.kunitconfig
acl.c ext4: convert to ctime accessor functions 2023-07-24 10:29:54 +02:00
acl.h Revert "ext4: apply umask if ACL support is disabled" 2024-05-02 18:25:39 -04:00
balloc.c ext4: add some kunit stub for mballoc kunit test 2023-10-05 22:32:16 -04:00
bitmap.c
block_validity.c ext4: block_validity: Remove unnecessary ‘NULL’ values from new_node 2024-06-27 09:34:00 -04:00
crypto.c fscrypt: support crypto data unit size less than filesystem block size 2023-09-25 22:34:33 -07:00
dir.c use ->bd_mapping instead of ->bd_inode->i_mapping 2024-05-03 02:36:51 -04:00
ext4.h ext4: use correct criteria name instead stale integer number in comment 2024-05-03 00:12:32 -04:00
ext4_extents.h
ext4_jbd2.c use ->bd_mapping instead of ->bd_inode->i_mapping 2024-05-03 02:36:51 -04:00
ext4_jbd2.h
extents.c ext4: set the type of max_zeroout to unsigned int to avoid overflow 2024-05-02 23:48:31 -04:00
extents_status.c ext4: fix infinite loop when replaying fast_commit 2024-06-27 10:26:28 -04:00
extents_status.h ext4: make ext4_es_insert_extent() return void 2023-06-26 19:35:12 -04:00
fast_commit.c ext4: make state in ext4_mb_mark_bb to be bool 2023-10-05 22:32:15 -04:00
fast_commit.h
file.c Ext4 patches for the 6.10-rc1 merge window: 2024-05-18 14:11:54 -07:00
fsmap.c ext4: port block device access to file 2024-02-25 12:05:26 +01:00
fsmap.h
fsync.c ext4: drop EXT4_MF_FS_ABORTED flag 2023-07-29 18:37:53 -04:00
hash.c ext4: remove redundant checks of s_encoding 2023-08-27 11:27:13 -04:00
ialloc.c ext4: convert to new timestamp accessors 2023-10-18 13:26:21 +02:00
indirect.c ext4: remove unnecessary parameter "needed" in ext4_discard_preallocations 2024-01-18 10:52:45 -05:00
inline.c ext4: fix uninitialized variable in ext4_inlinedir_to_tree 2024-06-27 10:08:36 -04:00
inode-test.c ext4: convert to ctime accessor functions 2023-07-24 10:29:54 +02:00
inode.c ext4: trim delalloc extent 2024-06-27 18:04:49 -04:00
ioctl.c ext4: replace deprecated strncpy with alternatives 2024-05-02 23:55:10 -04:00
Kconfig fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
Makefile
mballoc-test.c ext4: add test_mb_mark_used_cost to estimate cost of mb_mark_used 2024-05-03 00:12:32 -04:00
mballoc.c ext4: fix error pointer dereference in ext4_mb_load_buddy_gfp() 2024-05-17 11:24:38 -04:00
mballoc.h ext4: convert ac_buddy_page to ac_buddy_folio 2024-05-07 15:38:17 -04:00
migrate.c
mmp.c ext4: replace read-only check for shutdown check in mmp code 2023-07-29 18:37:53 -04:00
move_extent.c ext4: remove calls to to set/clear the folio error flag 2024-05-09 00:23:51 -04:00
namei.c ext4: avoid excessive credit estimate in ext4_tmpfile() 2024-05-02 14:49:16 -04:00
orphan.c
page-io.c ext4: remove calls to to set/clear the folio error flag 2024-05-09 00:23:51 -04:00
readpage.c ext4: remove calls to to set/clear the folio error flag 2024-05-09 00:23:51 -04:00
resize.c ext4: enable meta_bg only when new desc blocks are needed 2024-03-07 13:32:54 -05:00
super.c ext4: warn if delalloc counters are not zero on inactive 2024-06-27 18:04:49 -04:00
symlink.c ext4_get_link(): fix breakage in RCU mode 2024-02-25 02:10:32 -05:00
sysfs.c ext4: add positive int attr pointer to avoid sysfs variables overflow 2024-05-02 23:48:30 -04:00
truncate.h
verity.c
xattr.c ext4: propagate errors from ext4_sb_bread() in ext4_xattr_block_cache_find() 2024-05-07 15:59:18 -04:00
xattr.h ext4: move ext4_xattr_handlers to .rodata 2023-10-09 16:24:16 +02:00
xattr_hurd.c
xattr_security.c
xattr_trusted.c
xattr_user.c