From nobody Fri Sep 25 00:40:27 2026 Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0B283B4E87; Fri, 18 Sep 2026 10:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.59.177.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789726452; cv=none; b=T68A4fwZVzdUU3cJ/Dv65TbL6l3B2ncbsb628Lk+obt9vva8+hjd1HsNDTqqNdsPZt2udu+LkiGBdOwoeMcY3aQCzXokJ8bGyGRYepHVW7VAYcoBQeL5R4dsBT0bJrkJjAIODcUMqy5gJ6JlEPRGkwzSLho4Pu2BvhPx7kHhM98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789726452; c=relaxed/simple; bh=6YYj288nL3A7x7X8OeL7wLcwbvIuGI86AqM85QfuEA4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=WyQyNecYrn1DL/6OVdR78sWUxeJrSla4TvYNHZklDsgZeLLKJZCngQelO1tytttU2VzzS1ufwdWsESRbodCUJWFRFD0qngSP/FN876tqTpFwWsi1Xy1+Apy0stH54dr2oHM+xYKaF+igTP/K3F73j+H2lRO0yu2RQ91XrNvePcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=dZ2U+Hsp; arc=none smtp.client-ip=52.59.177.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="dZ2U+Hsp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1789726384; bh=z3rtAnpTaCBhOBulUgQk5hXYorxOdTRKUWGzxObqXF8=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=dZ2U+Hsp7rSa+1hgxworcyfoFhtySh91A7QnaQWiKYRQI57y+RCqygK3PWrJnyT7s EZGY7KBvCat9xOBWX0PoaZiajo99CeojSvwISeyjV3b3pMOp7Wj5gy+4WOHIJcp1bY 0Js784GJQbP6XSYobRnzEBFRtlCn05Kjz3vVmuq8= X-QQ-mid: esmtpsz16t1789726365t4b52b81f X-QQ-Originating-IP: 01JchSmDf3cfyE9ym0NCGe7/Ay5aYhAOf5Y/jluU7OI= Received: from uniontech.com ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 18 Sep 2026 18:12:43 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 11805283164246825907 EX-QQ-RecipientCnt: 11 From: Yichong Chen To: Theodore Ts'o Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Dilger , Baokun Li , Jan Kara , Ojaswin Mujoo , Ritesh Harjani , Zhang Yi , "Aneesh Kumar K . V" , Yichong Chen Subject: [PATCH] ext4: don't free the tmp_inode tree after a partial migration swap Date: Fri, 18 Sep 2026 18:12:40 +0800 Message-Id: <20260918101240.3721805-1-chenyichong@uniontech.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: esmtpsz:uniontech.com:qybglogicsvrgz:qybglogicsvrgz3a-0 X-QQ-XMAILINFO: OW4JKxETGMY2Biz6KcG/VPV6BeuQJN8dat0sTJjO6qRQ6sYRr76JaICM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Pm3vtSI1QTLgDHQqIV1w2oNKDqfg== X-QQ-RECHKSPAM: 0 Content-Type: text/plain; charset="utf-8" ext4_ext_migrate() cleans up the temporary inode when ext4_ext_swap_inode_data() fails: retval =3D 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") Signed-off-by: Yichong Chen Reviewed-by: Jan Kara --- fs/ext4/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index 2ce587043945..e588b4157604 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c @@ -562,7 +562,7 @@ int ext4_ext_migrate(struct inode *inode) free_ext_block(handle, tmp_inode); else { retval =3D 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 --=20 2.51.0