ext4: generalize EXT4_GET_BLOCKS_IO_SUBMIT flag usage
authorZhang Yi <yi.zhang@huawei.com>
Wed, 23 Apr 2025 08:52:50 +0000 (16:52 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 14 May 2025 14:42:12 +0000 (10:42 -0400)
Currently, the EXT4_GET_BLOCKS_IO_SUBMIT flag is only used during data
writeback to indicate that in ordered mode, the journal commit thread
should skip re-submitting data and simply wait for I/O completion.

To prepare for later patches that need to detect I/O submission context
in ext4_map_blocks(), generalizes the meaning of
EXT4_GET_BLOCKS_IO_SUBMIT. This flag will be set during:
 1) data I/O writeback,
 2) I/O completion extents conversion,
 3) journal performing commit in fast_commit.

This change doesn't affect current usage of this flag and provides a
clear way to identify I/O submission context.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Link: https://patch.msgid.link/20250423085257.122685-3-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/fast_commit.c

index 052d7afeefaf49615d97ed45f480cf3642989b4f..84cbe8024f1e705b26a30df00335c0977042b5c5 100644 (file)
@@ -706,9 +706,6 @@ enum {
 #define EXT4_GET_BLOCKS_CONVERT                        0x0010
 #define EXT4_GET_BLOCKS_IO_CREATE_EXT          (EXT4_GET_BLOCKS_PRE_IO|\
                                         EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
-       /* Convert extent to initialized after IO complete */
-#define EXT4_GET_BLOCKS_IO_CONVERT_EXT         (EXT4_GET_BLOCKS_CONVERT|\
-                                        EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
        /* 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
@@ -720,9 +717,15 @@ enum {
 #define EXT4_GET_BLOCKS_ZERO                   0x0200
 #define EXT4_GET_BLOCKS_CREATE_ZERO            (EXT4_GET_BLOCKS_CREATE |\
                                        EXT4_GET_BLOCKS_ZERO)
-       /* Caller will submit data before dropping transaction handle. This
-        * allows jbd2 to avoid submitting data before commit. */
+       /* Caller is in the context of data submission, such as writeback,
+        * fsync, etc. Especially, in the generic writeback path, caller will
+        * submit data before dropping transaction handle. This allows jbd2
+        * to avoid submitting data before commit. */
 #define EXT4_GET_BLOCKS_IO_SUBMIT              0x0400
+       /* Convert extent to initialized after IO complete */
+#define EXT4_GET_BLOCKS_IO_CONVERT_EXT         (EXT4_GET_BLOCKS_CONVERT |\
+                                        EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT |\
+                                        EXT4_GET_BLOCKS_IO_SUBMIT)
        /* Caller is in the atomic contex, find extent if it has been cached */
 #define EXT4_GET_BLOCKS_CACHED_NOWAIT          0x0800
 
index 7ac672e35f08c466b8372f250d8bdd38527766b7..bfe5b3c400781bce0c167f7d383c0f17ca06131a 100644 (file)
@@ -917,7 +917,8 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc)
        while (cur_lblk_off <= new_blk_size) {
                map.m_lblk = cur_lblk_off;
                map.m_len = new_blk_size - cur_lblk_off + 1;
-               ret = ext4_map_blocks(NULL, inode, &map, 0);
+               ret = ext4_map_blocks(NULL, inode, &map,
+                                     EXT4_GET_BLOCKS_IO_SUBMIT);
                if (ret < 0)
                        return -ECANCELED;