Skip to contentSkip to conversation

ext4: don't free the tmp_inode tree after a partial migration swap

PATCH Applied Yichong Chen 4 participants 4 messages Sep 18 – Nov 19 ext4 file system

lore
Share & tools
lore
#0 lore raw

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.

Fixes c14c6fd5c56a ("ext4: Add EXT4_IOC_MIGRATE ioctl")
---
 fs/ext4/migrate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/migrate.c +1 -1
index 2ce587043945..e588b4157604 100644
@@ -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
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines

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.

Quoted 5 lines

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.

Fixes c14c6fd5c56a ("ext4: Add EXT4_IOC_MIGRATE ioctl")

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
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Yichong Chen
Quoted 14 lines · Yichong Chen

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.

Quoted 5 lines

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.

Fixes c14c6fd5c56a ("ext4: Add EXT4_IOC_MIGRATE ioctl")

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
index 2ce587043945..e588b4157604 100644
@@ -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
maintainer Applied
#3 lore raw
In reply to Yichong Chen
Quoted 8 lines · Yichong Chen

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);

[...]

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]>