ext4: don't free the tmp_inode tree after a partial migration swap
PATCH 1/1 ext4: don't free the tmp_inode tree after a partial migration swap
ext4_ext_migrate() cleans up the temporary inode when ext4_ext_swap_inode_data() fails:
retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode); if (retval) free_ext_block(handle, tmp_inode);
ext4_ext_swap_inode_data() switches the inode to extents and copies the tree root into it before it frees the old indirect block map, so it can return an error after the swap has already happened. The copied root points at index blocks that tmp_inode allocated, and free_ext_block() walks that same tree and frees them, leaving the migrated inode with a tree node that the block bitmap considers free.
Only free the tmp_inode tree when the inode has not been switched to extents, which is exactly the case where the swap did not happen.
--- fs/ext4/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/migrate.c +1 -1
@@ -562,7 +562,7 @@ int ext4_ext_migrate(struct inode *inode)free_ext_block (handle, tmp_inode); else { retval =ext4_ext_swap_inode_data (handle, inode, tmp_inode); -if (retval) +if (retval && !ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))/* * if we fail to swap inode data free the extent * details of the tmp inode
Signature · 1 line
2.51.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines
ext4_ext_migrate()cleans up the temporary inode whenext4_ext_swap_inode_data()fails:retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode); if (retval) free_ext_block(handle, tmp_inode);
ext4_ext_swap_inode_data()switches the inode to extents and copies the tree root into it before it frees the old indirect block map, so it can return an error after the swap has already happened. The copied root points at index blocks thattmp_inodeallocated, andfree_ext_block()walks that same tree and frees them, leaving the migrated inode with a tree node that the block bitmap considers free.
Quoted 5 lines
Only free the
tmp_inodetree when the inode has not been switched to extents, which is exactly the case where the swap did not happen.Fixes c14c6fd5c56a ("ext4: Add EXT4_IOC_MIGRATE ioctl")Signed-off-by Yichong Chen <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 14 lines · Yichong Chen
ext4_ext_migrate()cleans up the temporary inode whenext4_ext_swap_inode_data()fails:retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode); if (retval) free_ext_block(handle, tmp_inode);
ext4_ext_swap_inode_data()switches the inode to extents and copies the tree root into it before it frees the old indirect block map, so it can return an error after the swap has already happened. The copied root points at index blocks thattmp_inodeallocated, andfree_ext_block()walks that same tree and frees them, leaving the migrated inode with a tree node that the block bitmap considers free.
Quoted 5 lines
Only free the
tmp_inodetree when the inode has not been switched to extents, which is exactly the case where the swap did not happen.Fixes c14c6fd5c56a ("ext4: Add EXT4_IOC_MIGRATE ioctl")Signed-off-by Yichong Chen <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 20 lines
--- fs/ext4/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ext4/migrate.c +1
-1@@ -562,7 +562,7 @@ int ext4_ext_migrate(struct inode *inode)free_ext_block (handle, tmp_inode); else { retval =ext4_ext_swap_inode_data (handle, inode, tmp_inode); -if (retval) +if (retval && !ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))/* * if we fail to swap inode data free the extent * details of the tmp inode Signature · 1 line
2.51.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Yichong Chen
ext4_ext_migrate()cleans up the temporary inode whenext4_ext_swap_inode_data()fails:retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode); if (retval) free_ext_block(handle, tmp_inode);[...]
Applied, thanks!
[1/1] ext4: don't free the tmp_inode tree after a partial migration swap
commit: 047061e6a6daac0fe2d647aa40d2f0783654f4c4
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>