From nobody Tue Dec 16 11:43:23 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B15CC28B2B for ; Fri, 19 Aug 2022 16:29:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352903AbiHSQ3F (ORCPT ); Fri, 19 Aug 2022 12:29:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353030AbiHSQ0C (ORCPT ); Fri, 19 Aug 2022 12:26:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B72510F689; Fri, 19 Aug 2022 09:03:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 207FAB82813; Fri, 19 Aug 2022 16:03:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BBBCC433C1; Fri, 19 Aug 2022 16:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925025; bh=/4ZOjVGkzyskBJxw7fJOb8dioi+LGEMss3iRlveg4x0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vFfUrYf0fZ47w+GUEKYqBVoHiwKhuOZbz9I96qIKtDPe2xyKpAgQqBH9u6USYn6IF eZYL+6JJ+udhkN/t2zyh1H6zd/368ybox8u/WB4t+SCufpCYknr9MsmHoAmp76WH9P NNo6M0QBSfW0bDlaVrPlcU4PYnE40KleaVhEH+Sg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Li Lingfeng , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 5.10 360/545] ext4: recover csum seed of tmp_inode after migrating to extents Date: Fri, 19 Aug 2022 17:42:10 +0200 Message-Id: <20220819153845.495249814@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Li Lingfeng [ Upstream commit 07ea7a617d6b278fb7acedb5cbe1a81ce2de7d0c ] When migrating to extents, the checksum seed of temporary inode need to be replaced by inode's, otherwise the inode checksums will be incorrect when swapping the inodes data. However, the temporary inode can not match it's checksum to itself since it has lost it's own checksum seed. mkfs.ext4 -F /dev/sdc mount /dev/sdc /mnt/sdc xfs_io -fc "pwrite 4k 4k" -c "fsync" /mnt/sdc/testfile chattr -e /mnt/sdc/testfile chattr +e /mnt/sdc/testfile umount /dev/sdc fsck -fn /dev/sdc =3D=3D=3D=3D=3D=3D=3D=3D ... Pass 1: Checking inodes, blocks, and sizes Inode 13 passes checks, but checksum does not match inode. Fix? no ... =3D=3D=3D=3D=3D=3D=3D=3D The fix is simple, save the checksum seed of temporary inode, and recover it after migrating to extents. Fixes: e81c9302a6c3 ("ext4: set csum seed in tmp inode while migrating to e= xtents") Signed-off-by: Li Lingfeng Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220617062515.2113438-1-lilingfeng3@huawei= .com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/migrate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index 49912814f3d8..04320715d61f 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c @@ -417,7 +417,7 @@ int ext4_ext_migrate(struct inode *inode) struct inode *tmp_inode =3D NULL; struct migrate_struct lb; unsigned long max_entries; - __u32 goal; + __u32 goal, tmp_csum_seed; uid_t owner[2]; =20 /* @@ -465,6 +465,7 @@ int ext4_ext_migrate(struct inode *inode) * the migration. */ ei =3D EXT4_I(inode); + tmp_csum_seed =3D EXT4_I(tmp_inode)->i_csum_seed; EXT4_I(tmp_inode)->i_csum_seed =3D ei->i_csum_seed; i_size_write(tmp_inode, i_size_read(inode)); /* @@ -575,6 +576,7 @@ int ext4_ext_migrate(struct inode *inode) * the inode is not visible to user space. */ tmp_inode->i_blocks =3D 0; + EXT4_I(tmp_inode)->i_csum_seed =3D tmp_csum_seed; =20 /* Reset the extent details */ ext4_ext_tree_init(handle, tmp_inode); --=20 2.35.1