Skip to contentSkip to conversation

fsck.f2fs: recover nat bits feature default by fsck

PATCH In review Yunlei He 3 participants 9 messages Apr 9, 2018 – Apr 13, 2018

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 fsck.f2fs: recover nat bits feature default by fsck

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +10 -5
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;
+		}
 		free(kaddr);
 	}
 	return 0;
Signature · 6 lines
1.9.1


------------------------------------------------------------------------------
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 14 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

Quoted 5 lines

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

Thanks,

------------------------------------------------------------------------------
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
In reply to Yunlei He
Quoted 42 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +1 -3
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2416

Quoted 10 lines
fsck/mount.c +8 -2
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;

What if kernel doesn't support this?

Quoted 6 lines
fsck/mount.c +1 -0
+		}
 		free(kaddr);
 	}
 	return 0;
Signature · 1 line
1.9.1

------------------------------------------------------------------------------
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
Quoted 56 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 12:01 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH] fsck.f2fs: recover nat bits feature default by fsck

Quoted 46 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +3 -5
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
Quoted 8 lines

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2416

Quoted 6 lines
fsck/mount.c +6 -0
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;

What if kernel doesn't support this?

Fix or write checkpoint now will enable nat bits by default if cp space is enough, So maybe it will not affect kernel not supporting nat bits?

Quoted 7 lines
Quoted 7 lines
fsck/mount.c +1 -1
+		}
 		free(kaddr);
 	}
 	return 0;
--

1.9.1

------------------------------------------------------------------------------
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 65 lines · heyunlei
Quoted 56 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 12:01 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH] fsck.f2fs: recover nat bits feature default by fsck

Quoted 46 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +3 -5
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
Quoted 8 lines

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2416

Quoted 6 lines
fsck/mount.c +6 -0
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;

What if kernel doesn't support this?

Quoted 2 lines

Fix or write checkpoint now will enable nat bits by default if cp space is enough, So maybe it will not affect kernel not supporting nat bits?

I don't think we really need this, since it mixes up whole thing.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
fsck/mount.c +1 -1
+		}
 		free(kaddr);
 	}
 	return 0;
--

1.9.1

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

#5 lore raw
Quoted 66 lines · Jaegeuk Kim
Quoted 65 lines · heyunlei
Quoted 64 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 12:01 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH] fsck.f2fs: recover nat bits feature default by fsck

Quoted 42 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +1 -3
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2416

Quoted 10 lines
fsck/mount.c +8 -2
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;

What if kernel doesn't support this?

Quoted 4 lines
Quoted 2 lines

Fix or write checkpoint now will enable nat bits by default if cp space is enough, So maybe it will not affect kernel not supporting nat bits?

I don't think we really need this, since it mixes up whole thing.

IIUC, Yunlei just want use a flag to detect *real* data corruption on-line, then it can be a condition to end up issuing discard from background/umount/fstrim to prevent further data losing.

For that, as I suggested before, we can split in-memory SBI_NEED_FSCK to SBI_LOSE_NAT_BIT and SBI_NEED_FSCK, for backward compatibility, on-disk flag can still be old one as below:

update_ckpt_flags()

if (SBI_NEED_FSCK || SBI_LOSE_NAT_BIT)
set_cp_flag(CP_FSCK_FLAG)

How about that?

Thanks,

Quoted 12 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
fsck/mount.c +1 -1
+		}
 		free(kaddr);
 	}
 	return 0;
--

1.9.1

.

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

#6 lore raw
Quoted 80 lines · Chao Yu
Quoted 66 lines · Jaegeuk Kim
Quoted 65 lines · heyunlei
Quoted 64 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 12:01 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH] fsck.f2fs: recover nat bits feature default by fsck

Quoted 42 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +1 -3
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2416

Quoted 10 lines
fsck/mount.c +8 -2
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;

What if kernel doesn't support this?

Quoted 4 lines
Quoted 2 lines

Fix or write checkpoint now will enable nat bits by default if cp space is enough, So maybe it will not affect kernel not supporting nat bits?

I don't think we really need this, since it mixes up whole thing.

IIUC, Yunlei just want use a flag to detect *real* data corruption on-line, then it can be a condition to end up issuing discard from background/umount/fstrim to prevent further data losing.

For that, as I suggested before, we can split in-memory SBI_NEED_FSCK to SBI_LOSE_NAT_BIT and SBI_NEED_FSCK, for backward compatibility, on-disk flag can still be old one as below:

Quoted 6 lines

update_ckpt_flags()

if (SBI_NEED_FSCK || SBI_LOSE_NAT_BIT)
set_cp_flag(CP_FSCK_FLAG)

How about that?

I don't think we need to add more complexity here which will give another bug later. Blocking discards would make sense tho, I don't think nat_bits should be together with it.

Thanks,

Quoted 15 lines

Thanks,

Quoted 12 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
fsck/mount.c +1 -1
+		}
 		free(kaddr);
 	}
 	return 0;
--

1.9.1

.

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

#7 lore raw
Quoted 83 lines · Jaegeuk Kim
Quoted 82 lines · Chao Yu
Quoted 66 lines · Jaegeuk Kim
Quoted 65 lines · heyunlei
Quoted 64 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 12:01 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH] fsck.f2fs: recover nat bits feature default by fsck

Quoted 42 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +1 -3
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2416

Quoted 10 lines
fsck/mount.c +8 -2
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;

What if kernel doesn't support this?

Quoted 4 lines
Quoted 2 lines

Fix or write checkpoint now will enable nat bits by default if cp space is enough, So maybe it will not affect kernel not supporting nat bits?

I don't think we really need this, since it mixes up whole thing.

IIUC, Yunlei just want use a flag to detect *real* data corruption on-line, then it can be a condition to end up issuing discard from background/umount/fstrim to prevent further data losing.

For that, as I suggested before, we can split in-memory SBI_NEED_FSCK to SBI_LOSE_NAT_BIT and SBI_NEED_FSCK, for backward compatibility, on-disk flag can still be old one as below:

update_ckpt_flags()

Quoted 8 lines
Quoted 4 lines

if (SBI_NEED_FSCK || SBI_LOSE_NAT_BIT)
set_cp_flag(CP_FSCK_FLAG)

How about that?

I don't think we need to add more complexity here which will give another bug later. Blocking discards would make sense tho, I don't think nat_bits should be together with it.

We need a more clear flag to indicate that filesystem is corrupted to decide blocking discard, instead of using current flag which includes a state indicate losing nat_bits.

So what's your opinion? keep as it is?

Thanks,

Quoted 19 lines

Thanks,

Quoted 15 lines

Thanks,

Quoted 12 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
fsck/mount.c +1 -1
+		}
 		free(kaddr);
 	}
 	return 0;
--

1.9.1

.

Quoted 2 lines

.

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

author
#8 lore raw
In reply to Jaegeuk Kim
Quoted 56 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, April 10, 2018 12:01 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Zhangdianfang (Euler)
Subject: Re: [f2fs-dev][PATCH] fsck.f2fs: recover nat bits feature default by fsck

Quoted 46 lines · Yunlei He

Now, nat bits feature is enabled by default, we will meet with the following scenarios:

i. disabled, without CP_NAT_BITS_FLAG, if fsck find some
fs errors, fix or write new checkpoint will then enable it.
ii. enabled, with CP_NAT_BITS_FLAG, in the case of sudden
power off, bitmap will get lost but CP_NAT_BITS_FLAG still exist, fsck will recover bitmap in f2fs_do_mount.
iii. enabled, with CP_NAT_BITS_FLAG, both of bitmap and
CP_NAT_BITS_FLAG will get lost if not enough space for nat bits or nat bits check failed during mounting. SBI_NEED_FSCK is set, fsck will recover flag and bitmap before next mount.

SBI_NEED_FSCK means fs is corrupted, is not suitable for nat bits disabled. This patch try to recover nat bits all by fsck, no need set SBI_NEED_FSCK flag in kernel.

---
 fsck/mount.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
fsck/mount.c +3 -5
index e5574c5..2361ee0 100644
@@ -2389,7 +2389,7 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 
 	/* Check nat_bits */
-	if (c.func != DUMP && is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+	if (c.func != DUMP) {
 		u_int32_t nat_bits_bytes, nat_bits_blocks;
 		__le64 *kaddr;
 		u_int32_t blk;
@@ -2406,10 +2406,15 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		kaddr = malloc(PAGE_SIZE);
 		ret = dev_read_block(kaddr, blk);
 		ASSERT(ret >= 0);
-		if (*kaddr != get_cp_crc(cp))
-			write_nat_bits(sbi, sb, cp, sbi->cur_cp);
-		else
-			MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		if(is_set_ckpt_flags(cp, CP_NAT_BITS_FLAG)) {
+			if (*kaddr != get_cp_crc(cp))
Quoted 8 lines

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2416

Quoted 6 lines
fsck/mount.c +6 -0
+				write_nat_bits(sbi, sb, cp, sbi->cur_cp);
+			else
+				MSG(0, "Info: Found valid nat_bits in checkpoint\n");
+		} else if (c.func == FSCK){
+			ASSERT_MSG("Need to recover nat_bits.");
+			c.fix_on = 1;

What if kernel doesn't support this?

How about patch as below:

@@ -1055,6 +1055,7 @@ enum {

        SBI_POR_DOING,                          /* recovery is doing or not */
        SBI_NEED_SB_WRITE,                      /* need to recover superblock */
        SBI_NEED_CP,                            /* need to checkpoint */
+       SBI_DISABLE_NAT_BITS,                   /* disable nat bits temporay */

};

enum {
@@ -1517,11 +1518,10 @@ static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)

 {
        unsigned long flags;

- set_sbi_flag(sbi, SBI_NEED_FSCK);
+ set_sbi_flag(sbi, SBI_DISABLE_NAT_BITS);

        if (lock)
                spin_lock_irqsave(&sbi->cp_lock, flags);
-       __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
        kfree(NM_I(sbi)->nat_bits);
        NM_I(sbi)->nat_bits = NULL;
        if (lock)

@@ -1531,7 +1531,8 @@ static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
struct cp_control *cpc)
{
- bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
+ bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG) &&
+ !is_sbi_flag_set(sbi, SBI_DISABLE_NAT_BITS);

        return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;

}

Thanks.

Quoted 7 lines
Quoted 7 lines
fsck/mount.c +1 -1
+		}
 		free(kaddr);
 	}
 	return 0;
--

1.9.1

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