]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ext4: rename EXT4_GET_BLOCKS_PRE_IO
authorYang Erkun <yangerkun@huawei.com>
Wed, 12 Nov 2025 08:45:36 +0000 (16:45 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 26 Nov 2025 22:13:33 +0000 (17:13 -0500)
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>
fs/ext4/ext4.h
fs/ext4/extents.c
fs/ext4/inode.c
include/trace/events/ext4.h

index 9f127aedbaeeb054341ae1c454225cf16054d692..9df4f3ddfe42e52384ed734e23c5f57dd4299702 100644 (file)
@@ -695,13 +695,22 @@ enum {
        /* Caller is from the delayed allocation writeout path
         * finally doing the actual allocation of delayed blocks */
 #define EXT4_GET_BLOCKS_DELALLOC_RESERVE       0x0004
-       /* caller is from the direct IO path, request to creation of an
-       unwritten extents if not allocated, split the unwritten
-       extent if blocks has been preallocated already*/
-#define EXT4_GET_BLOCKS_PRE_IO                 0x0008
-#define EXT4_GET_BLOCKS_CONVERT                        0x0010
-#define EXT4_GET_BLOCKS_IO_CREATE_EXT          (EXT4_GET_BLOCKS_PRE_IO|\
+       /*
+        * This means that we cannot merge newly allocated extents, and if we
+        * found an unwritten extent, we need to split it.
+        */
+#define EXT4_GET_BLOCKS_SPLIT_NOMERGE          0x0008
+       /*
+        * Caller is from the dio or dioread_nolock buffered IO, reqest to
+        * create an unwritten extent if it does not exist or split the
+        * found unwritten extent. Also do not merge the newly created
+        * unwritten extent, io end will convert unwritten to written,
+        * and try to merge the written extent.
+        */
+#define EXT4_GET_BLOCKS_IO_CREATE_EXT          (EXT4_GET_BLOCKS_SPLIT_NOMERGE|\
                                         EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
+       /* Convert unwritten extent to initialized. */
+#define EXT4_GET_BLOCKS_CONVERT                        0x0010
        /* Eventual metadata allocation (due to growing extent tree)
         * should not fail, so try to use reserved blocks for that.*/
 #define EXT4_GET_BLOCKS_METADATA_NOFAIL                0x0020
index c7d219e6c6d89f2b0b5121414c09cdbcc8b8c36b..b9be5d8320de62a2ddece929c88a5607a90e0f5b 100644 (file)
@@ -333,7 +333,7 @@ ext4_force_split_extent_at(handle_t *handle, struct inode *inode,
                           int nofail)
 {
        int unwritten = ext4_ext_is_unwritten(path[path->p_depth].p_ext);
-       int flags = EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_PRE_IO;
+       int flags = EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_SPLIT_NOMERGE;
 
        if (nofail)
                flags |= EXT4_GET_BLOCKS_METADATA_NOFAIL | EXT4_EX_NOFAIL;
@@ -2002,7 +2002,7 @@ ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
        }
 
        /* try to insert block into found extent and return */
-       if (ex && !(gb_flags & EXT4_GET_BLOCKS_PRE_IO)) {
+       if (ex && !(gb_flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE)) {
 
                /*
                 * Try to see whether we should rather test the extent on
@@ -2181,7 +2181,7 @@ has_space:
 
 merge:
        /* try to merge extents */
-       if (!(gb_flags & EXT4_GET_BLOCKS_PRE_IO))
+       if (!(gb_flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE))
                ext4_ext_try_to_merge(handle, inode, path, nearex);
 
        /* time to correct all indexes above */
@@ -3224,7 +3224,7 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,
                else
                        ext4_ext_mark_initialized(ex);
 
-               if (!(flags & EXT4_GET_BLOCKS_PRE_IO))
+               if (!(flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE))
                        ext4_ext_try_to_merge(handle, inode, path, ex);
 
                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,
 
        if (map->m_lblk + map->m_len < ee_block + ee_len) {
                split_flag1 = split_flag & EXT4_EXT_MAY_ZEROOUT;
-               flags1 = flags | EXT4_GET_BLOCKS_PRE_IO;
+               flags1 = flags | EXT4_GET_BLOCKS_SPLIT_NOMERGE;
                if (unwritten)
                        split_flag1 |= EXT4_EXT_MARK_UNWRIT1 |
                                       EXT4_EXT_MARK_UNWRIT2;
@@ -3739,7 +3739,7 @@ static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle,
                              EXT4_EXT_MAY_ZEROOUT : 0;
                split_flag |= (EXT4_EXT_MARK_UNWRIT2 | EXT4_EXT_DATA_VALID2);
        }
-       flags |= EXT4_GET_BLOCKS_PRE_IO;
+       flags |= EXT4_GET_BLOCKS_SPLIT_NOMERGE;
        return ext4_split_extent(handle, inode, path, map, split_flag, flags,
                                 allocated);
 }
@@ -3911,7 +3911,7 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode,
                                                *allocated, newblock);
 
        /* get_block() before submitting IO, split the extent */
-       if (flags & EXT4_GET_BLOCKS_PRE_IO) {
+       if (flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE) {
                path = ext4_split_convert_extents(handle, inode, map, path,
                                flags | EXT4_GET_BLOCKS_CONVERT, allocated);
                if (IS_ERR(path))
@@ -5618,7 +5618,7 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
                        path = ext4_split_extent_at(handle, inode, path,
                                        start_lblk, split_flag,
                                        EXT4_EX_NOCACHE |
-                                       EXT4_GET_BLOCKS_PRE_IO |
+                                       EXT4_GET_BLOCKS_SPLIT_NOMERGE |
                                        EXT4_GET_BLOCKS_METADATA_NOFAIL);
                }
 
index 32d9f0b36c33a0529a5c527cfb0792a195a610fe..3883793425cb124753352e1a06fffb80ba62e090 100644 (file)
@@ -653,7 +653,7 @@ static int ext4_map_create_blocks(handle_t *handle, struct inode *inode,
         * If the extent has been zeroed out, we don't need to update
         * extent status tree.
         */
-       if (flags & EXT4_GET_BLOCKS_PRE_IO &&
+       if (flags & EXT4_GET_BLOCKS_SPLIT_NOMERGE &&
            ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es, &map->m_seq)) {
                if (ext4_es_is_written(&es))
                        return retval;
index a05bdd48e16eaec9a39bfebbce2f94d2ce139a47..fd76d14c2776ec789f94ca3f98b802eee73ca9f6 100644 (file)
@@ -39,7 +39,7 @@ struct partial_cluster;
        { EXT4_GET_BLOCKS_CREATE,               "CREATE" },             \
        { EXT4_GET_BLOCKS_UNWRIT_EXT,           "UNWRIT" },             \
        { EXT4_GET_BLOCKS_DELALLOC_RESERVE,     "DELALLOC" },           \
-       { EXT4_GET_BLOCKS_PRE_IO,               "PRE_IO" },             \
+       { EXT4_GET_BLOCKS_SPLIT_NOMERGE,        "SPLIT_NOMERGE" },      \
        { EXT4_GET_BLOCKS_CONVERT,              "CONVERT" },            \
        { EXT4_GET_BLOCKS_METADATA_NOFAIL,      "METADATA_NOFAIL" },    \
        { EXT4_GET_BLOCKS_NO_NORMALIZE,         "NO_NORMALIZE" },       \