Skip to contentSkip to conversation

fsck.f2fs: check extent of inline data/dentry inode

PATCH In review Sheng Yong 2 participants 5 messages Jul 3, 2018 – Jul 9, 2018

lore
Share & tools
lore

Sheng Yong

author
#0 lore raw

PATCH 1/2 fsck.f2fs: check extent of inline data/dentry inode

Check extent for inline data/dentry inode. If an inode contains inline data/dentry, it should have no extent.

---
 fsck/fsck.c | 16 +++++++++++-----
 fsck/fsck.h |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)
fsck/fsck.c +11 -5
index 6fd9dc2..15264b2 100644
@@ -584,6 +584,9 @@ static void check_extent_info(struct child_info *child,
 	if (child->state & FSCK_UNMATCHED_EXTENT)
 		return;
 
+	if ((child->state & FSCK_INLINE_INODE) && ei->len)
+		goto unmatched;
+
 	if (last) {
 		/* hole exist in the back of extent */
 		if (child->last_blk != ei->blk + ei->len - 1)
@@ -735,6 +738,10 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 	}
 	ofs = get_extra_isize(node_blk);
 
+	/* init extent info */
+	get_extent_info(&child.ei, &node_blk->i.i_ext);
+	child.last_blk = 0;
+
 	if ((node_blk->i.i_inline & F2FS_INLINE_DATA)) {
 		if (le32_to_cpu(node_blk->i.i_addr[ofs]) != 0) {
 			/* should fix this bug all the time */
@@ -756,6 +763,7 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 			}
 		}
 		DBG(3, "ino[0x%x] has inline data!\n", nid);
+		child.state |= FSCK_INLINE_INODE;
 		goto check;
 	}
 
@@ -775,13 +783,10 @@ void fsck_chk_inode_blk(struct f2fs_sb_info *sbi, u32 nid,
 			/* should fix this bug all the time */
 			need_fix = 1;
 		}
+		child.state |= FSCK_INLINE_INODE;
 		goto check;
 	}
 
-	/* init extent info */
-	get_extent_info(&child.ei, &node_blk->i.i_ext);
-	child.last_blk = 0;
-
 	/* check data blocks in inode */
 	for (idx = 0; idx < ADDRS_PER_INODE(&node_blk->i);
 						idx++, child.pgofs++) {
@@ -851,6 +856,7 @@ skip:
 
 	}
 
+check:
 	/* check uncovered range in the back of extent */
 	check_extent_info(&child, 0, 1);
 
@@ -860,7 +866,7 @@ skip:
 		if (c.fix_on)
 			need_fix = 1;
 	}
-check:
+
 	if (i_blocks != *blk_cnt) {
 		ASSERT_MSG("ino: 0x%x has i_blocks: %08"PRIx64", "
 				"but has %u blocks",
fsck/fsck.h +1 -0
index 5530aff..f620912 100644
@@ -16,6 +16,7 @@
 struct quota_ctx;
 
 #define FSCK_UNMATCHED_EXTENT		0x00000001
+#define FSCK_INLINE_INODE		0x00000002
 
 enum {
 	PREEN_MODE_0,
Signature · 6 lines
2.17.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
author
#1 lore raw

PATCH 2/2 fsck.f2fs: check extra_attr feature

Check extra_attr feature for inode. If it is corrupted, remove the inode.

---
 fsck/fsck.c | 6 ++++++
 1 file changed, 6 insertions(+)
fsck/fsck.c +6 -0
index 15264b2..acbe25d 100644
@@ -460,6 +460,12 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
 		__check_inode_mode(nid, ftype, le32_to_cpu(node_blk->i.i_mode)))
 		return -EINVAL;
 
+	if (ntype == TYPE_INODE &&
+			((f2fs_has_extra_isize(&node_blk->i) &&
+			  !(c.feature & F2FS_FEATURE_EXTRA_ATTR)) ||
+			 get_extra_isize(node_blk) >= DEF_ADDRS_PER_INODE))
+		return -EINVAL;
+
 	/* workaround to fix later */
 	if (ftype != F2FS_FT_ORPHAN ||
 			f2fs_test_bit(nid, fsck->nat_area_bitmap) != 0) {
Signature · 6 lines
2.17.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
#2 lore raw

Re: [PATCH 2/2] fsck.f2fs: check extra_attr feature

Hi Sheng,

Quoted 2 lines · Sheng Yong

Check extra_attr feature for inode. If it is corrupted, remove the inode.

Could you check the patch:

[PATCH] fsck.f2fs: fix to do sanity check with extra_attr feature

Would it better to do sanity check with it in fsck_chk_inode_blk? since it is about consistence of inode instead of nid.

Thanks,

Quoted 16 lines
---
 fsck/fsck.c | 6 ++++++
 1 file changed, 6 insertions(+)
fsck/fsck.c +0 -0
index 15264b2..acbe25d 100644
@@ -460,6 +460,12 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
 		__check_inode_mode(nid, ftype, le32_to_cpu(node_blk->i.i_mode)))
 		return -EINVAL;

fsck/fsck.c static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid, · line 471

Quoted 10 lines
fsck/fsck.c +6 -0
 
+	if (ntype == TYPE_INODE &&
+			((f2fs_has_extra_isize(&node_blk->i) &&
+			  !(c.feature & F2FS_FEATURE_EXTRA_ATTR)) ||
+			 get_extra_isize(node_blk) >= DEF_ADDRS_PER_INODE))
+		return -EINVAL;
+
 	/* workaround to fix later */
 	if (ftype != F2FS_FT_ORPHAN ||
 			f2fs_test_bit(nid, fsck->nat_area_bitmap) != 0) {

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

author
#3 lore raw

Re: [PATCH 2/2] fsck.f2fs: check extra_attr feature

Quoted 6 lines · Chao Yu

Hi Sheng,

Quoted 2 lines · Sheng Yong

Check extra_attr feature for inode. If it is corrupted, remove the inode.

Quoted 7 lines

Could you check the patch:

[PATCH] fsck.f2fs: fix to do sanity check with extra_attr feature

Would it better to do sanity check with it in fsck_chk_inode_blk? since it is about consistence of inode instead of nid.

Agree. And the patch has already checked the value of i_extra_isize, so this one can be dropped :-)

Thanks

Quoted 18 lines

Thanks,

Quoted 16 lines
---
  fsck/fsck.c | 6 ++++++
  1 file changed, 6 insertions(+)
fsck/fsck.c +0 -0
index 15264b2..acbe25d 100644
@@ -460,6 +460,12 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
  		__check_inode_mode(nid, ftype, le32_to_cpu(node_blk->i.i_mode)))
  		return -EINVAL;
 
Quoted 14 lines

fsck/fsck.c static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid, · line 471

Quoted 10 lines
fsck/fsck.c +6 -0
+	if (ntype == TYPE_INODE &&
+			((f2fs_has_extra_isize(&node_blk->i) &&
+			  !(c.feature & F2FS_FEATURE_EXTRA_ATTR)) ||
+			 get_extra_isize(node_blk) >= DEF_ADDRS_PER_INODE))
+		return -EINVAL;
+
  	/* workaround to fix later */
  	if (ftype != F2FS_FT_ORPHAN ||
  			f2fs_test_bit(nid, fsck->nat_area_bitmap) != 0) {

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Reviewed-by on v1 1/2
#4 lore raw
In reply to Sheng Yong
Quoted 6 lines · Sheng Yong

Check extent for inline data/dentry inode. If an inode contains inline data/dentry, it should have no extent.

Thanks,

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot