Skip to content

Commit dac0921

Browse files
Yang Erkuntytso
authored andcommitted
ext4: rename EXT4_GET_BLOCKS_PRE_IO
This flag has been generalized to split an unwritten extent when we do dio or dioread_nolock writeback, or to avoid merge new extents which was created by extents split. Update some related comments too. Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Baokun Li <libaokun1@huawei.com> Signed-off-by: Yang Erkun <yangerkun@huawei.com> Message-ID: <20251112084538.1658232-2-yangerkun@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent d9ee3ff commit dac0921

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

fs/ext4/ext4.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,22 @@ enum {
695695
/* Caller is from the delayed allocation writeout path
696696
* finally doing the actual allocation of delayed blocks */
697697
#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004
698-
/* caller is from the direct IO path, request to creation of an
699-
unwritten extents if not allocated, split the unwritten
700-
extent if blocks has been preallocated already*/
701-
#define EXT4_GET_BLOCKS_PRE_IO 0x0008
702-
#define EXT4_GET_BLOCKS_CONVERT 0x0010
703-
#define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\
698+
/*
699+
* This means that we cannot merge newly allocated extents, and if we
700+
* found an unwritten extent, we need to split it.
701+
*/
702+
#define EXT4_GET_BLOCKS_SPLIT_NOMERGE 0x0008
703+
/*
704+
* Caller is from the dio or dioread_nolock buffered IO, reqest to
705+
* create an unwritten extent if it does not exist or split the
706+
* found unwritten extent. Also do not merge the newly created
707+
* unwritten extent, io end will convert unwritten to written,
708+
* and try to merge the written extent.
709+
*/
710+
#define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_SPLIT_NOMERGE|\
704711
EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
712+
/* Convert unwritten extent to initialized. */
713+
#define EXT4_GET_BLOCKS_CONVERT 0x0010
705714
/* Eventual metadata allocation (due to growing extent tree)
706715
* should not fail, so try to use reserved blocks for that.*/
707716
#define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020

fs/ext4/extents.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ ext4_force_split_extent_at(handle_t *handle, struct inode *inode,
333333
int nofail)
334334
{
335335
int unwritten = ext4_ext_is_unwritten(path[path->p_depth].p_ext);
336-
int flags = EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_PRE_IO;
336+
int flags = EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_SPLIT_NOMERGE;
337337

338338
if (nofail)
339339
flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL | EXT4_EX_NOFAIL;
@@ -2002,7 +2002,7 @@ ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
20022002
}
20032003

20042004
/* try to insert block into found extent and return */
2005-
if (ex && !(gb_flags & EXT4_GET_BLOCKS_PRE_IO)) {
2005+
if (ex && !(gb_flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE)) {
20062006

20072007
/*
20082008
* Try to see whether we should rather test the extent on
@@ -2181,7 +2181,7 @@ ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
21812181

21822182
merge:
21832183
/* try to merge extents */
2184-
if (!(gb_flags & EXT4_GET_BLOCKS_PRE_IO))
2184+
if (!(gb_flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE))
21852185
ext4_ext_try_to_merge(handle, inode, path, nearex);
21862186

21872187
/* time to correct all indexes above */
@@ -3224,7 +3224,7 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
32243224
else
32253225
ext4_ext_mark_initialized(ex);
32263226

3227-
if (!(flags & EXT4_GET_BLOCKS_PRE_IO))
3227+
if (!(flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE))
32283228
ext4_ext_try_to_merge(handle, inode, path, ex);
32293229

32303230
err = ext4_ext_dirty(handle, inode, path + path->p_depth);
@@ -3368,7 +3368,7 @@ static struct ext4_ext_path *ext4_split_extent(handle_t *handle,
33683368

33693369
if (map->m_lblk + map->m_len < ee_block + ee_len) {
33703370
split_flag1 = split_flag & EXT4_EXT_MAY_ZEROOUT;
3371-
flags1 = flags | EXT4_GET_BLOCKS_PRE_IO;
3371+
flags1 = flags | EXT4_GET_BLOCKS_SPLIT_NOMERGE;
33723372
if (unwritten)
33733373
split_flag1 |= EXT4_EXT_MARK_UNWRIT1 |
33743374
EXT4_EXT_MARK_UNWRIT2;
@@ -3739,7 +3739,7 @@ static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle,
37393739
EXT4_EXT_MAY_ZEROOUT : 0;
37403740
split_flag |= (EXT4_EXT_MARK_UNWRIT2 | EXT4_EXT_DATA_VALID2);
37413741
}
3742-
flags |= EXT4_GET_BLOCKS_PRE_IO;
3742+
flags |= EXT4_GET_BLOCKS_SPLIT_NOMERGE;
37433743
return ext4_split_extent(handle, inode, path, map, split_flag, flags,
37443744
allocated);
37453745
}
@@ -3911,7 +3911,7 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
39113911
*allocated, newblock);
39123912

39133913
/* get_block() before submitting IO, split the extent */
3914-
if (flags & EXT4_GET_BLOCKS_PRE_IO) {
3914+
if (flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE) {
39153915
path = ext4_split_convert_extents(handle, inode, map, path,
39163916
flags | EXT4_GET_BLOCKS_CONVERT, allocated);
39173917
if (IS_ERR(path))
@@ -5618,7 +5618,7 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
56185618
path = ext4_split_extent_at(handle, inode, path,
56195619
start_lblk, split_flag,
56205620
EXT4_EX_NOCACHE |
5621-
EXT4_GET_BLOCKS_PRE_IO |
5621+
EXT4_GET_BLOCKS_SPLIT_NOMERGE |
56225622
EXT4_GET_BLOCKS_METADATA_NOFAIL);
56235623
}
56245624

fs/ext4/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
653653
* If the extent has been zeroed out, we don't need to update
654654
* extent status tree.
655655
*/
656-
if (flags & EXT4_GET_BLOCKS_PRE_IO &&
656+
if (flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE &&
657657
ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es, &map->m_seq)) {
658658
if (ext4_es_is_written(&es))
659659
return retval;

include/trace/events/ext4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct partial_cluster;
3939
{ EXT4_GET_BLOCKS_CREATE, "CREATE" }, \
4040
{ EXT4_GET_BLOCKS_UNWRIT_EXT, "UNWRIT" }, \
4141
{ EXT4_GET_BLOCKS_DELALLOC_RESERVE, "DELALLOC" }, \
42-
{ EXT4_GET_BLOCKS_PRE_IO, "PRE_IO" }, \
42+
{ EXT4_GET_BLOCKS_SPLIT_NOMERGE, "SPLIT_NOMERGE" }, \
4343
{ EXT4_GET_BLOCKS_CONVERT, "CONVERT" }, \
4444
{ EXT4_GET_BLOCKS_METADATA_NOFAIL, "METADATA_NOFAIL" }, \
4545
{ EXT4_GET_BLOCKS_NO_NORMALIZE, "NO_NORMALIZE" }, \

0 commit comments

Comments
 (0)