Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate()
@ 2026-09-10  5:29 Yichong Chen
  2026-09-10  5:43 ` sashiko-bot
  2026-09-10 10:17 ` Jan Kara
  0 siblings, 2 replies; 3+ messages in thread
From: Yichong Chen @ 2026-09-10  5:29 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: linux-ext4, linux-kernel, Andreas Dilger, Baokun Li, Jan Kara,
	Ojaswin Mujoo, Ritesh Harjani, Zhang Yi, Yichong Chen

ext4_ext_migrate() records the failure of the migration in retval, but
ext4_journal_ensure_credits() overwrites it: it returns 0 when the handle
has enough credits or the transaction could be extended, and 1 when the
transaction had to be restarted.  A failed migration is therefore
reported as success, and a restart leaks the internal value 1 to
userspace through EXT4_IOC_MIGRATE and FS_IOC_SETFLAGS.

Fixes: a413036791d0 ("ext4: Provide function to handle transaction restarts")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
---
 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 2aa6572088cf..e06d847033a1 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.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-10 10:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-10  5:29 [PATCH] ext4: don't clobber the migration error in ext4_ext_migrate() Yichong Chen
2026-09-10  5:43 ` sashiko-bot
2026-09-10 10:17 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox