Since commit a413036791d0 ("ext4: Provide function to handle transaction restarts") ext4_ext_migrate() overwrites its result with the return value of the final ext4_journal_ensure_credits(). So if building the extent tree fails, e.g., with ENOSPC, or ext4_ext_swap_inode_data() returns EAGAIN because a block got allocated in the meantime, we report success and the inode stays block mapped. And if the handle had to be restarted we return 1 to FS_IOC_SETFLAGS and EXT4_IOC_MIGRATE. Keep the result of the migration and only return the error of the credit check if nothing else failed. Fixes: a413036791d0 ("ext4: Provide function to handle transaction restarts") Signed-off-by: Christian Brauner (Amutable) --- fs/ext4/migrate.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index 09931d3ba2c6a..be48456fa76f3 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c @@ -410,7 +410,7 @@ static int free_ext_block(handle_t *handle, struct inode *inode) int ext4_ext_migrate(struct inode *inode) { handle_t *handle; - int retval = 0, i; + int retval = 0, err, i; __le32 *i_data; struct ext4_inode_info *ei; struct inode *tmp_inode = NULL; @@ -567,9 +567,12 @@ int ext4_ext_migrate(struct inode *inode) } /* We mark the tmp_inode dirty via ext4_ext_tree_init. */ - retval = ext4_journal_ensure_credits(handle, 1, 0); - if (retval < 0) + err = ext4_journal_ensure_credits(handle, 1, 0); + if (err < 0) { + if (!retval) + retval = err; goto out_stop; + } /* * Mark the tmp_inode as of size zero */ -- 2.53.0