Skip to content

ext4: fix error handling of failed migration

Lukas Czerner linux-ext4 1 version Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 1 replyApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/2ext4: fix failed migrate freeing extent tree blocksfs/ext4/ext4.h fs/ext4/extents.c fs/ext4/migrate.c+23 -20 replies
2/2ext4: don't lose the error of a failed migrationfs/ext4/migrate.c+6 -30 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] ext4: fix error handling of failed migration

When converting an inode from indirect blocks to extents (the EXT4_IOC_MIGRATE ioctl) fails, two problems can show up.

ext4_ext_swap_inode_data() can fail after the temporary inode's extent tree has already been copied into the original inode. The error path then frees the extent tree blocks via the temporary inode, leaving the filesystem with multiply claimed blocks. Fix it by resetting the temporary inode's extent tree and i_blocks right after the copy, so the cleanup can neither free the original inode's extent tree blocks nor truncate its data.

Also, ext4_journal_ensure_credits() overwrites whatever error the migration ran into previously, so the ioctl reports success even though the migration failed. Use a separate variable for its return value.

Tested with xfstests quick with defaults, home-brewed EXT4_IOC_MIGRATE stress test and a reproducer written by AI.

Lukas Czerner (2):
ext4: fix failed migrate freeing extent tree blocks
ext4: don't lose the error of a failed migration

 fs/ext4/ext4.h    |  1 +
 fs/ext4/extents.c | 11 ++++++++++-
 fs/ext4/migrate.c | 22 ++++++++++++++++++----
 3 files changed, 29 insertions(+), 5 deletions(-)

base-commit: 5b0764a53235d3c77e1ed674e836e1b3fe1a4b1f

Signature · 1 line
2.56.0