linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 2/4] fsck.f2fs: fix to check c.fix_on before repair
Date: Thu, 15 Aug 2019 18:06:36 -0700	[thread overview]
Message-ID: <20190816010636.GB66488@jaegeuk-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <20190812114527.34613-2-yuchao0@huawei.com>

On 08/12, Chao Yu wrote:
> We should always set c.bug_on whenever found a bug, then fix them
> if c.fix_on is on, otherwise, some bugs won't be shown unless we
> enable debug log.
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  fsck/fsck.c | 137 +++++++++++++++++++++++++++++++---------------------
>  1 file changed, 83 insertions(+), 54 deletions(-)
> 
> diff --git a/fsck/fsck.c b/fsck/fsck.c
> index 7eb599d..91ddd49 100644
> --- a/fsck/fsck.c
> +++ b/fsck/fsck.c
> @@ -712,12 +712,13 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
>  	fsck_reada_node_block(sbi, le32_to_cpu(node_blk->i.i_xattr_nid));
>  
>  	if (fsck_chk_xattr_blk(sbi, nid,
> -			le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt) &&
> -			c.fix_on) {
> -		node_blk->i.i_xattr_nid = 0;
> -		need_fix = 1;
> -		FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
> -				nid, le32_to_cpu(node_blk->i.i_xattr_nid));
> +			le32_to_cpu(node_blk->i.i_xattr_nid), blk_cnt)) {
> +		if (c.fix_on) {
> +			node_blk->i.i_xattr_nid = 0;
> +			need_fix = 1;
> +			FIX_MSG("Remove xattr block: 0x%x, x_nid = 0x%x",
> +					nid, le32_to_cpu(node_blk->i.i_xattr_nid));
> +		}

Why do we need this change?

>  	}
>  
>  	if (ftype == F2FS_FT_CHRDEV || ftype == F2FS_FT_BLKDEV ||
> @@ -730,24 +731,32 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
>  
>  	if (f2fs_has_extra_isize(&node_blk->i)) {
>  		if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR)) {
> -			if (node_blk->i.i_extra_isize >
> -				cpu_to_le16(F2FS_TOTAL_EXTRA_ATTR_SIZE)) {
> -				FIX_MSG("ino[0x%x] recover i_extra_isize "
> -					"from %u to %u",
> -					nid,
> -					le16_to_cpu(node_blk->i.i_extra_isize),
> -					calc_extra_isize());
> -				node_blk->i.i_extra_isize =
> -					cpu_to_le16(calc_extra_isize());
> -				need_fix = 1;
> +			unsigned int isize =
> +				le16_to_cpu(node_blk->i.i_extra_isize);
> +
> +			if (isize > F2FS_TOTAL_EXTRA_ATTR_SIZE) {
> +				ASSERT_MSG("[0x%x] wrong i_extra_isize=0x%x",
> +						nid, isize);
> +				if (c.fix_on) {
> +					FIX_MSG("ino[0x%x] recover i_extra_isize "
> +						"from %u to %u",
> +						nid, isize,
> +						calc_extra_isize());
> +					node_blk->i.i_extra_isize =
> +						cpu_to_le16(calc_extra_isize());
> +					need_fix = 1;
> +				}
>  			}
>  		} else {
> -			FIX_MSG("ino[0x%x] remove F2FS_EXTRA_ATTR "
> -				"flag in i_inline:%u",
> -				nid, node_blk->i.i_inline);
> -			/* we don't support tuning F2FS_FEATURE_EXTRA_ATTR now */
> -			node_blk->i.i_inline &= ~F2FS_EXTRA_ATTR;
> -			need_fix = 1;
> +			ASSERT_MSG("[0x%x] wrong extra_attr flag", nid);
> +			if (c.fix_on) {
> +				FIX_MSG("ino[0x%x] remove F2FS_EXTRA_ATTR "
> +					"flag in i_inline:%u",
> +					nid, node_blk->i.i_inline);
> +				/* we don't support tuning F2FS_FEATURE_EXTRA_ATTR now */
> +				node_blk->i.i_inline &= ~F2FS_EXTRA_ATTR;
> +				need_fix = 1;
> +			}
>  		}
>  
>  		if ((c.feature &
> @@ -758,13 +767,17 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
>  
>  			if (!inline_size ||
>  					inline_size > MAX_INLINE_XATTR_SIZE) {
> -				FIX_MSG("ino[0x%x] recover inline xattr size "
> -					"from %u to %u",
> -					nid, inline_size,
> -					DEFAULT_INLINE_XATTR_ADDRS);
> -				node_blk->i.i_inline_xattr_size =
> -					cpu_to_le16(DEFAULT_INLINE_XATTR_ADDRS);
> -				need_fix = 1;
> +				ASSERT_MSG("[0x%x] wrong inline_xattr_size:%u",
> +						nid, inline_size);
> +				if (c.fix_on) {
> +					FIX_MSG("ino[0x%x] recover inline xattr size "
> +						"from %u to %u",
> +						nid, inline_size,
> +						DEFAULT_INLINE_XATTR_ADDRS);
> +					node_blk->i.i_inline_xattr_size =
> +						cpu_to_le16(DEFAULT_INLINE_XATTR_ADDRS);
> +					need_fix = 1;
> +				}
>  			}
>  		}
>  	}
> @@ -772,20 +785,28 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
>  
>  	if ((node_blk->i.i_inline & F2FS_INLINE_DATA)) {
>  		unsigned int inline_size = MAX_INLINE_DATA(node_blk);
> +		block_t blkaddr = le32_to_cpu(node_blk->i.i_addr[ofs]);
>  
> -		if (le32_to_cpu(node_blk->i.i_addr[ofs]) != 0) {
> -			/* should fix this bug all the time */
> -			FIX_MSG("inline_data has wrong 0'th block = %x",
> -					le32_to_cpu(node_blk->i.i_addr[ofs]));
> -			node_blk->i.i_addr[ofs] = 0;
> -			node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
> -			need_fix = 1;
> +		if (blkaddr != 0) {
> +			ASSERT_MSG("[0x%x] wrong inline reserve blkaddr:%u",
> +					nid, blkaddr);
> +			if (c.fix_on) {
> +				FIX_MSG("inline_data has wrong 0'th block = %x",
> +								blkaddr);
> +				node_blk->i.i_addr[ofs] = 0;
> +				node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
> +				need_fix = 1;
> +			}
>  		}
>  		if (!i_size || i_size > inline_size) {
> -			node_blk->i.i_size = cpu_to_le64(inline_size);
> -			FIX_MSG("inline_data has wrong i_size %lu",
> -						(unsigned long)i_size);
> -			need_fix = 1;
> +			ASSERT_MSG("[0x%x] wrong inline size:%lu",
> +					nid, (unsigned long)i_size);
> +			if (c.fix_on) {
> +				node_blk->i.i_size = cpu_to_le64(inline_size);
> +				FIX_MSG("inline_data has wrong i_size %lu",
> +							(unsigned long)i_size);
> +				need_fix = 1;
> +			}
>  		}
>  		if (!(node_blk->i.i_inline & F2FS_DATA_EXIST)) {
>  			char buf[MAX_INLINE_DATA(node_blk)];
> @@ -793,9 +814,12 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
>  
>  			if (memcmp(buf, inline_data_addr(node_blk),
>  						MAX_INLINE_DATA(node_blk))) {
> -				FIX_MSG("inline_data has DATA_EXIST");
> -				node_blk->i.i_inline |= F2FS_DATA_EXIST;
> -				need_fix = 1;
> +				ASSERT_MSG("[0x%x] junk inline data", nid);
> +				if (c.fix_on) {
> +					FIX_MSG("inline_data has DATA_EXIST");
> +					node_blk->i.i_inline |= F2FS_DATA_EXIST;
> +					need_fix = 1;
> +				}
>  			}
>  		}
>  		DBG(3, "ino[0x%x] has inline data!\n", nid);
> @@ -804,20 +828,25 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
>  	}
>  
>  	if ((node_blk->i.i_inline & F2FS_INLINE_DENTRY)) {
> +		block_t blkaddr = le32_to_cpu(node_blk->i.i_addr[ofs]);
> +
>  		DBG(3, "ino[0x%x] has inline dentry!\n", nid);
> -		if (le32_to_cpu(node_blk->i.i_addr[ofs]) != 0) {
> -			/* should fix this bug all the time */
> -			FIX_MSG("inline_dentry has wrong 0'th block = %x",
> -					le32_to_cpu(node_blk->i.i_addr[ofs]));
> -			node_blk->i.i_addr[ofs] = 0;
> -			node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
> -			need_fix = 1;
> +		if (blkaddr != 0) {
> +			ASSERT_MSG("[0x%x] wrong inline reserve blkaddr:%u",
> +								nid, blkaddr);
> +			if (c.fix_on) {
> +				FIX_MSG("inline_dentry has wrong 0'th block = %x",
> +								blkaddr);
> +				node_blk->i.i_addr[ofs] = 0;
> +				node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
> +				need_fix = 1;
> +			}
>  		}
>  
>  		ret = fsck_chk_inline_dentries(sbi, node_blk, &child);
>  		if (ret < 0) {
> -			/* should fix this bug all the time */
> -			need_fix = 1;
> +			if (c.fix_on)
> +				need_fix = 1;
>  		}
>  		child.state |= FSCK_INLINE_INODE;
>  		goto check;
> @@ -999,7 +1028,7 @@ skip_blkcnt_fix:
>  	free(en);
>  
>  	if (ftype == F2FS_FT_SYMLINK && i_blocks && i_size == 0) {
> -		DBG(1, "ino: 0x%x i_blocks: %lu with zero i_size",
> +		ASSERT_MSG("ino: 0x%x i_blocks: %lu with zero i_size\n",
>  						nid, (unsigned long)i_blocks);
>  		if (c.fix_on) {
>  			u64 i_size = i_blocks * F2FS_BLKSIZE;
> @@ -1012,7 +1041,7 @@ skip_blkcnt_fix:
>  	}
>  
>  	if (ftype == F2FS_FT_ORPHAN && i_links) {
> -		MSG(0, "ino: 0x%x is orphan inode, but has i_links: %u",
> +		ASSERT_MSG("ino: 0x%x is orphan inode, but has i_links: %u",
>  				nid, i_links);
>  		if (c.fix_on) {
>  			node_blk->i.i_links = 0;
> -- 
> 2.18.0.rc1


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2019-08-16  1:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-12 11:45 [f2fs-dev] [PATCH 1/4] fsck.f2fs: fix to recover out-of-border inline size Chao Yu
2019-08-12 11:45 ` [f2fs-dev] [PATCH 2/4] fsck.f2fs: fix to check c.fix_on before repair Chao Yu
2019-08-16  1:06   ` Jaegeuk Kim [this message]
2019-08-16  1:20     ` Chao Yu
2019-08-20 11:34       ` Chao Yu
2019-08-12 11:45 ` [f2fs-dev] [PATCH 3/4] fsck.f2fs: fix to show removed x_nid correctly Chao Yu
2019-08-12 11:45 ` [f2fs-dev] [PATCH 4/4] fsck.f2fs: fix symlink correctly Chao Yu
2019-08-15 22:39 ` [f2fs-dev] [PATCH 1/4] fsck.f2fs: fix to recover out-of-border inline size Jaegeuk Kim
2019-08-16  1:03   ` Jaegeuk Kim

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=20190816010636.GB66488@jaegeuk-macbookpro.roam.corp.google.com \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=yuchao0@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).