Skip to contentSkip to conversation

mkfs.f2fs: fix wrong curseg check

PATCH In review Jaegeuk Kim 3 participants 5 messages Aug 26, 2017 – Sep 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.f2fs: fix wrong curseg check

We should avoid i==j, otherwise we always assign 0~5 segments.

---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +1 -1
index b379e80..219c2a7 100644
@@ -123,7 +123,7 @@ static void verify_cur_segs(void)
 
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		for (j = 0; j < NR_CURSEG_TYPE; j++)
-			if (c.cur_seg[i] == c.cur_seg[j])
+			if (i != j && c.cur_seg[i] == c.cur_seg[j])
 				break;
 	}
 
Signature · 6 lines
2.14.0.rc1.383.gd1ce394fe2-goog


------------------------------------------------------------------------------
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/1
#1 lore raw
Quoted 3 lines · Jaegeuk Kim

We should avoid i==j, otherwise we always assign 0~5 segments.

Quoted 10 lines
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index b379e80..219c2a7 100644

mkfs/f2fs_format.c static void verify_cur_segs(void) · line 129

Quoted 8 lines
mkfs/f2fs_format.c +1 -1
@@ -123,7 +123,7 @@ static void verify_cur_segs(void)
 
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		for (j = 0; j < NR_CURSEG_TYPE; j++)
-			if (c.cur_seg[i] == c.cur_seg[j])
+			if (i != j && c.cur_seg[i] == c.cur_seg[j])
 				break;
 	}
 

------------------------------------------------------------------------------
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

Hi Jaegeuk,

I still can hit kernel panic with this patch, the reason is reorder of log header during mkfs is not actually executed, it needs to change as below.

Quoted 17 lines · Chao Yu
Quoted 3 lines · Jaegeuk Kim

We should avoid i==j, otherwise we always assign 0~5 segments.

Quoted 10 lines
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index b379e80..219c2a7 100644
@@ -123,7 +123,7 @@ static void verify_cur_segs(void)
 
Quoted 5 lines

mkfs/f2fs_format.c static void verify_cur_segs(void) · line 127

Quoted 5 lines
mkfs/f2fs_format.c +1 -1
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		for (j = 0; j < NR_CURSEG_TYPE; j++)
-			if (c.cur_seg[i] == c.cur_seg[j])
+			if (i != j && c.cur_seg[i] == c.cur_seg[j])
 				break;
	if (i != j && c.cur_seg[i] == c.cur_seg[j])
		goto reorder;

return;

reorder:
c.cur_seg[0] = 0;

Thanks,

Quoted 5 lines

mkfs/f2fs_format.c static void verify_cur_segs(void) · line 129

Quoted 3 lines
mkfs/f2fs_format.c +0 -0
 	}
 
Quoted 8 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

author Reviewed-by Chao Yu
#3 lore raw
Quoted 23 lines · Chao Yu

Hi Jaegeuk,

I still can hit kernel panic with this patch, the reason is reorder of log header during mkfs is not actually executed, it needs to change as below.

Quoted 17 lines · Chao Yu
Quoted 3 lines · Jaegeuk Kim

We should avoid i==j, otherwise we always assign 0~5 segments.

Quoted 10 lines
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index b379e80..219c2a7 100644
@@ -123,7 +123,7 @@ static void verify_cur_segs(void)
 
Quoted 7 lines
Quoted 5 lines

mkfs/f2fs_format.c static void verify_cur_segs(void) · line 127

Quoted 5 lines
mkfs/f2fs_format.c +1 -1
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		for (j = 0; j < NR_CURSEG_TYPE; j++)
-			if (c.cur_seg[i] == c.cur_seg[j])
+			if (i != j && c.cur_seg[i] == c.cur_seg[j])
 				break;
	if (i != j && c.cur_seg[i] == c.cur_seg[j])

Can be overflowed?

How about this?

Quoted 1 line

From 53923f74b188028c4f5a8b64b330f0d7b12adf24 Mon Sep 17 00:00:00 2001

From: Jaegeuk Kim <[email protected]>
Date: Thu, 24 Aug 2017 19:33:10 -0700
Subject: [PATCH] mkfs.f2fs: fix wrong curseg check

We should avoid i==j, otherwise we always assign 0~5 segments.

---
 mkfs/f2fs_format.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +7 -3
index b379e80..8319f24 100644
@@ -120,14 +120,18 @@ next:
 static void verify_cur_segs(void)
 {
 	int i, j;
+	bool reorder = false;
 
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
-		for (j = 0; j < NR_CURSEG_TYPE; j++)
-			if (c.cur_seg[i] == c.cur_seg[j])
+		for (j = i + 1; j < NR_CURSEG_TYPE; j++) {
+			if (c.cur_seg[i] == c.cur_seg[j]) {
+				reorder = true;
 				break;
+			}
+		}
 	}
 
-	if (i == NR_CURSEG_TYPE && j == NR_CURSEG_TYPE)
+	if (!reorder)
 		return;
 
 	c.cur_seg[0] = 0;
Signature · 6 lines
2.14.0.rc1.383.gd1ce394fe2-goog


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
#4 lore raw
Quoted 32 lines · Jaegeuk Kim
Quoted 23 lines · Chao Yu

Hi Jaegeuk,

I still can hit kernel panic with this patch, the reason is reorder of log header during mkfs is not actually executed, it needs to change as below.

Quoted 17 lines · Chao Yu
Quoted 3 lines · Jaegeuk Kim

We should avoid i==j, otherwise we always assign 0~5 segments.

Quoted 10 lines
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mkfs/f2fs_format.c +0 -0
index b379e80..219c2a7 100644
@@ -123,7 +123,7 @@ static void verify_cur_segs(void)
 
Quoted 7 lines
Quoted 5 lines

mkfs/f2fs_format.c next: · line 129

Quoted 5 lines
mkfs/f2fs_format.c +1 -1
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		for (j = 0; j < NR_CURSEG_TYPE; j++)
-			if (c.cur_seg[i] == c.cur_seg[j])
+			if (i != j && c.cur_seg[i] == c.cur_seg[j])
 				break;
	if (i != j && c.cur_seg[i] == c.cur_seg[j])
Quoted 3 lines

Can be overflowed?

How about this?

It's OK to me. :)

Thanks,

Quoted 31 lines
Quoted 2 lines

From 53923f74b188028c4f5a8b64b330f0d7b12adf24 Mon Sep 17 00:00:00 2001

From: Jaegeuk Kim <[email protected]>
Date: Thu, 24 Aug 2017 19:33:10 -0700
Subject: [PATCH] mkfs.f2fs: fix wrong curseg check

We should avoid i==j, otherwise we always assign 0~5 segments.

---
 mkfs/f2fs_format.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +4 -2
index b379e80..8319f24 100644
@@ -120,14 +120,18 @@ next:
 static void verify_cur_segs(void)
 {
 	int i, j;
+	bool reorder = false;
 
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
-		for (j = 0; j < NR_CURSEG_TYPE; j++)
-			if (c.cur_seg[i] == c.cur_seg[j])
+		for (j = i + 1; j < NR_CURSEG_TYPE; j++) {
+			if (c.cur_seg[i] == c.cur_seg[j]) {
+				reorder = true;

mkfs/f2fs_format.c next: · line 137

Quoted 10 lines
mkfs/f2fs_format.c +3 -1
 				break;
+			}
+		}
 	}
 
-	if (i == NR_CURSEG_TYPE && j == NR_CURSEG_TYPE)
+	if (!reorder)
 		return;
 
 	c.cur_seg[0] = 0;

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