]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ext4: fix insufficient credits calculation in ext4_meta_trans_blocks()
authorZhang Yi <yi.zhang@huawei.com>
Mon, 7 Jul 2025 14:08:13 +0000 (22:08 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 15 Aug 2025 14:39:07 +0000 (16:39 +0200)
[ Upstream commit 5137d6c8906b55b3c7b5d1aa5a549753ec8520f5 ]

The calculation of journal credits in ext4_meta_trans_blocks() should
include pextents, as each extent separately may be allocated from a
different group and thus need to update different bitmap and group
descriptor block.

Fixes: 0e32d8617012 ("ext4: correct the journal credits calculations of allocating blocks")
Reported-by: Jan Kara <jack@suse.cz>
Closes: https://lore.kernel.org/linux-ext4/nhxfuu53wyacsrq7xqgxvgzcggyscu2tbabginahcygvmc45hy@t4fvmyeky33e/
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Baokun Li <libaokun1@huawei.com>
Link: https://patch.msgid.link/20250707140814.542883-11-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext4/inode.c

index be9a4cba35fd523adce76b3b22a9677fbd86264b..85edd1edaa6e792afeb3d86d9b427195e67c0030 100644 (file)
@@ -6139,7 +6139,7 @@ int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents)
        int ret;
 
        /*
-        * How many index and lead blocks need to touch to map @lblocks
+        * How many index and leaf blocks need to touch to map @lblocks
         * logical blocks to @pextents physical extents?
         */
        idxblocks = ext4_index_trans_blocks(inode, lblocks, pextents);
@@ -6148,7 +6148,7 @@ int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents)
         * Now let's see how many group bitmaps and group descriptors need
         * to account
         */
-       groups = idxblocks;
+       groups = idxblocks + pextents;
        gdpblocks = groups;
        if (groups > ngroups)
                groups = ngroups;