All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Li Lingfeng <lilingfeng3@huawei.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu,
	adilger.kernel@dilger.ca, linux-kernel@vger.kernel.org,
	jack@suse.cz, yi.zhang@huawei.com, yukuai3@huawei.com,
	libaokun2@huawei.com
Subject: Re: [PATCH -next] ext4: recover csum seed of tmp_inode after migrating to extents
Date: Fri, 17 Jun 2022 12:44:41 +0200	[thread overview]
Message-ID: <20220617104441.lfhuca6tflg2oxah@quack3.lan> (raw)
In-Reply-To: <20220617062515.2113438-1-lilingfeng3@huawei.com>

On Fri 17-06-22 14:25:15, Li Lingfeng wrote:
> 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
> 
> ========
> ...
> Pass 1: Checking inodes, blocks, and sizes
> Inode 13 passes checks, but checksum does not match inode.  Fix? no
> ...
> ========
> 
> 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 extents")
> Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>

Yeah, the migration code and checksums never quite worked together. That's
the reason why we'd decided to deprecate this code. But I guess this fix is
simple enough and improves things so feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  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 = NULL;
>  	struct migrate_struct lb;
>  	unsigned long max_entries;
> -	__u32 goal;
> +	__u32 goal, tmp_csum_seed;
>  	uid_t owner[2];
>  
>  	/*
> @@ -465,6 +465,7 @@ int ext4_ext_migrate(struct inode *inode)
>  	 * the migration.
>  	 */
>  	ei = EXT4_I(inode);
> +	tmp_csum_seed = EXT4_I(tmp_inode)->i_csum_seed;
>  	EXT4_I(tmp_inode)->i_csum_seed = 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 = 0;
> +	EXT4_I(tmp_inode)->i_csum_seed = tmp_csum_seed;
>  
>  	/* Reset the extent details */
>  	ext4_ext_tree_init(handle, tmp_inode);
> -- 
> 2.31.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2022-06-17 10:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17  6:25 [PATCH -next] ext4: recover csum seed of tmp_inode after migrating to extents Li Lingfeng
2022-06-17 10:44 ` Jan Kara [this message]
2022-07-22 13:58 ` Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220617104441.lfhuca6tflg2oxah@quack3.lan \
    --to=jack@suse.cz \
    --cc=adilger.kernel@dilger.ca \
    --cc=libaokun2@huawei.com \
    --cc=lilingfeng3@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.