Skip to contentSkip to conversation

fsck.f2fs: avoid fix ssa in some case

PATCH Superseded Yunlei He 2 participants 3 messages Jan 28, 2016 – Jan 30, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 fsck.f2fs: avoid fix ssa in some case

In some case, we need confirm node or data blkaddr is ok at first, and then fix the conflict in ssa block. If the node blkaddr happen to locate in data type segment caused by something error, may be we 'd better ignore it, and it's same with data blkaddr.

---
 fsck/fsck.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
fsck/fsck.c +25 -9
index e7dd02f..fd82bef 100644
@@ -129,6 +129,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
 {
 	struct f2fs_summary_block *sum_blk;
 	struct f2fs_summary *sum_entry;
+	struct seg_entry * se;
 	u32 segno, offset;
 	int need_fix = 0, ret = 0;
 	int type;
@@ -145,9 +146,16 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
 			ret = -EINVAL;
 			goto out;
 		}
-		FIX_MSG("Summary footer indicates a node segment: 0x%x", segno);
-		sum_blk->footer.entry_type = SUM_TYPE_NODE;
+
 		need_fix = 1;
+		se = get_seg_entry(sbi, segno);
+		if(se->type >= 3 && se->type <= 5) {
+			FIX_MSG("Summary footer indicates a node segment: 0x%x", segno);
+			sum_blk->footer.entry_type = SUM_TYPE_NODE;
+		} else {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 
 	sum_entry = &(sum_blk->entries[offset]);
@@ -235,6 +243,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
 {
 	struct f2fs_summary_block *sum_blk;
 	struct f2fs_summary *sum_entry;
+	struct seg_entry * se;
 	u32 segno, offset;
 	int need_fix = 0, ret = 0;
 	int type;
@@ -251,9 +260,16 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
 			ret = -EINVAL;
 			goto out;
 		}
-		FIX_MSG("Summary footer indicates a data segment: 0x%x", segno);
-		sum_blk->footer.entry_type = SUM_TYPE_DATA;
+
 		need_fix = 1;
+		se = get_seg_entry(sbi, segno);
+		if (se->type >=0 && se->type <= 2) {
+			FIX_MSG("Summary footer indicates a data segment: 0x%x", segno);
+			sum_blk->footer.entry_type = SUM_TYPE_DATA;
+		} else {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 
 	sum_entry = &(sum_blk->entries[offset]);
@@ -352,11 +368,6 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
 		return -EINVAL;
 	}
 
-	if (is_valid_ssa_node_blk(sbi, nid, ni->blk_addr)) {
-		ASSERT_MSG("summary node block is not valid. [0x%x]", nid);
-		return -EINVAL;
-	}
-
 	ret = dev_read_block(node_blk, ni->blk_addr);
 	ASSERT(ret >= 0);
 
@@ -427,6 +438,11 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
 		ASSERT_MSG("orphan or xattr nid is duplicated [0x%x]\n",
 				nid);
 
+	if (is_valid_ssa_node_blk(sbi, nid, ni->blk_addr)) {
+		ASSERT_MSG("summary node block is not valid. [0x%x]", nid);
+		return -EINVAL;
+	}
+
 	if (f2fs_test_sit_bitmap(sbi, ni->blk_addr) == 0)
 		ASSERT_MSG("SIT bitmap is 0x0. blk_addr[0x%x]",
 				ni->blk_addr);
Signature · 9 lines
1.9.1


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
#1 lore raw

Hi Yunlei,

Quoted 23 lines · Yunlei He

In some case, we need confirm node or data blkaddr is ok at first, and then fix the conflict in ssa block. If the node blkaddr happen to locate in data type segment caused by something error, may be we 'd better ignore it, and it's same with data blkaddr.

---
 fsck/fsck.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
fsck/fsck.c +1 -0
index e7dd02f..fd82bef 100644
@@ -129,6 +129,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
 {
 	struct f2fs_summary_block *sum_blk;
 	struct f2fs_summary *sum_entry;
+	struct seg_entry * se;
 	u32 segno, offset;
 	int need_fix = 0, ret = 0;
 	int type;

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

Quoted 9 lines
fsck/fsck.c +3 -2
@@ -145,9 +146,16 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
 			ret = -EINVAL;
 			goto out;
 		}
-		FIX_MSG("Summary footer indicates a node segment: 0x%x", segno);
-		sum_blk->footer.entry_type = SUM_TYPE_NODE;
+
 		need_fix = 1;
+		se = get_seg_entry(sbi, segno);
+		if(se->type >= 3 && se->type <= 5) {

IS_NODESEG(se->type) ?

Quoted 18 lines
fsck/fsck.c +7 -0
+			FIX_MSG("Summary footer indicates a node segment: 0x%x", segno);
+			sum_blk->footer.entry_type = SUM_TYPE_NODE;
+		} else {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 
 	sum_entry = &(sum_blk->entries[offset]);
@@ -235,6 +243,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
 {
 	struct f2fs_summary_block *sum_blk;
 	struct f2fs_summary *sum_entry;
+	struct seg_entry * se;
 	u32 segno, offset;
 	int need_fix = 0, ret = 0;
 	int type;

fsck/fsck.c static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr, · line 266

Quoted 9 lines
fsck/fsck.c +3 -2
@@ -251,9 +260,16 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
 			ret = -EINVAL;
 			goto out;
 		}
-		FIX_MSG("Summary footer indicates a data segment: 0x%x", segno);
-		sum_blk->footer.entry_type = SUM_TYPE_DATA;
+
 		need_fix = 1;
+		se = get_seg_entry(sbi, segno);
+		if (se->type >=0 && se->type <= 2) {

IS_DATASEG(se->type) ?

Quoted 47 lines
fsck/fsck.c +11 -5
+			FIX_MSG("Summary footer indicates a data segment: 0x%x", segno);
+			sum_blk->footer.entry_type = SUM_TYPE_DATA;
+		} else {
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 
 	sum_entry = &(sum_blk->entries[offset]);
@@ -352,11 +368,6 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
 		return -EINVAL;
 	}
 
-	if (is_valid_ssa_node_blk(sbi, nid, ni->blk_addr)) {
-		ASSERT_MSG("summary node block is not valid. [0x%x]", nid);
-		return -EINVAL;
-	}
-
 	ret = dev_read_block(node_blk, ni->blk_addr);
 	ASSERT(ret >= 0);
 
@@ -427,6 +438,11 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
 		ASSERT_MSG("orphan or xattr nid is duplicated [0x%x]\n",
 				nid);
 
+	if (is_valid_ssa_node_blk(sbi, nid, ni->blk_addr)) {
+		ASSERT_MSG("summary node block is not valid. [0x%x]", nid);
+		return -EINVAL;
+	}
+
 	if (f2fs_test_sit_bitmap(sbi, ni->blk_addr) == 0)
 		ASSERT_MSG("SIT bitmap is 0x0. blk_addr[0x%x]",
 				ni->blk_addr);
Signature · 13 lines
1.9.1


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140

author
#2 lore raw
Quoted 59 lines · Jaegeuk Kim

Hi Yunlei,

Quoted 23 lines · Yunlei He

In some case, we need confirm node or data blkaddr is ok at first, and then fix the conflict in ssa block. If the node blkaddr happen to locate in data type segment caused by something error, may be we 'd better ignore it, and it's same with data blkaddr.

---
  fsck/fsck.c | 34 +++++++++++++++++++++++++---------
  1 file changed, 25 insertions(+), 9 deletions(-)
fsck/fsck.c +1 -0
index e7dd02f..fd82bef 100644
@@ -129,6 +129,7 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
  {
  	struct f2fs_summary_block *sum_blk;
  	struct f2fs_summary *sum_entry;
+	struct seg_entry * se;
  	u32 segno, offset;
  	int need_fix = 0, ret = 0;
  	int type;

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

Quoted 9 lines
fsck/fsck.c +3 -2
@@ -145,9 +146,16 @@ static int is_valid_ssa_node_blk(struct f2fs_sb_info *sbi, u32 nid,
  			ret = -EINVAL;
  			goto out;
  		}
-		FIX_MSG("Summary footer indicates a node segment: 0x%x", segno);
-		sum_blk->footer.entry_type = SUM_TYPE_NODE;
+
  		need_fix = 1;
+		se = get_seg_entry(sbi, segno);
+		if(se->type >= 3 && se->type <= 5) {

IS_NODESEG(se->type) ?

Quoted 21 lines
fsck/fsck.c +7 -0
+			FIX_MSG("Summary footer indicates a node segment: 0x%x", segno);
+			sum_blk->footer.entry_type = SUM_TYPE_NODE;
+		} else {
+			ret = -EINVAL;
+			goto out;
+		}
  	}
 
  	sum_entry = &(sum_blk->entries[offset]);
@@ -235,6 +243,7 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
  {
  	struct f2fs_summary_block *sum_blk;
  	struct f2fs_summary *sum_entry;
+	struct seg_entry * se;
  	u32 segno, offset;
  	int need_fix = 0, ret = 0;
  	int type;
@@ -251,9 +260,16 @@ static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr,
  			ret = -EINVAL;
  			goto out;
  		}
Quoted 8 lines

fsck/fsck.c static int is_valid_ssa_data_blk(struct f2fs_sb_info *sbi, u32 blk_addr, · line 266

Quoted 6 lines
fsck/fsck.c +3 -2
-		FIX_MSG("Summary footer indicates a data segment: 0x%x", segno);
-		sum_blk->footer.entry_type = SUM_TYPE_DATA;
+
  		need_fix = 1;
+		se = get_seg_entry(sbi, segno);
+		if (se->type >=0 && se->type <= 2) {

IS_DATASEG(se->type) ?

yeah, it's good!

Thanks.

Quoted 38 lines
Quoted 38 lines
fsck/fsck.c +11 -6
+			FIX_MSG("Summary footer indicates a data segment: 0x%x", segno);
+			sum_blk->footer.entry_type = SUM_TYPE_DATA;
+		} else {
+			ret = -EINVAL;
+			goto out;
+		}
  	}
 
  	sum_entry = &(sum_blk->entries[offset]);
@@ -352,11 +368,6 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
  		return -EINVAL;
  	}
 
-	if (is_valid_ssa_node_blk(sbi, nid, ni->blk_addr)) {
-		ASSERT_MSG("summary node block is not valid. [0x%x]", nid);
-		return -EINVAL;
-	}
-
  	ret = dev_read_block(node_blk, ni->blk_addr);
  	ASSERT(ret >= 0);
 
@@ -427,6 +438,11 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
  		ASSERT_MSG("orphan or xattr nid is duplicated [0x%x]\n",
  				nid);
 
+	if (is_valid_ssa_node_blk(sbi, nid, ni->blk_addr)) {
+		ASSERT_MSG("summary node block is not valid. [0x%x]", nid);
+		return -EINVAL;
+	}
+
  	if (f2fs_test_sit_bitmap(sbi, ni->blk_addr) == 0)
  		ASSERT_MSG("SIT bitmap is 0x0. blk_addr[0x%x]",
  				ni->blk_addr);
--

1.9.1

Quoted 13 lines
Quoted 10 lines

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

.

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140