Skip to contentSkip to conversation

f2fs: fix wrong segment count

PATCH In review Jaegeuk Kim 2 participants 6 messages Feb 10, 2023 – Feb 14, 2023 F2FS file system

lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix wrong segment count

MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.

---
 fs/f2fs/segment.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/segment.h +2 -2
index 8ee5e5db9287..6003fbaf4b7d 100644
@@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
 
 static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
 {
-	f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
+	f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1);
 }
 
 static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)
@@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
 
 	/* check segment usage, and check boundary of a given segment number */
 	if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg
-					|| segno > TOTAL_SEGS(sbi) - 1)) {
+					|| segno > MAIN_SEGS(sbi) - 1)) {
 		f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
 			 GET_SIT_VBLOCKS(raw_sit), segno);
 		set_sbi_flag(sbi, SBI_NEED_FSCK);
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
maintainer
#1 lore raw
Quoted 1 line · Jaegeuk Kim

MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.

Good catch!

Could you please add fixes line?

Thanks,

Quoted 20 lines
---
  fs/f2fs/segment.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/segment.h +1 -1
index 8ee5e5db9287..6003fbaf4b7d 100644
@@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
 
  static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
  {
-	f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
+	f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1);
  }
 
  static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)

fs/f2fs/segment.h static inline int check_block_count(struct f2fs_sb_info *sbi, · line 781

Quoted 8 lines
fs/f2fs/segment.h +1 -1
@@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
 
  	/* check segment usage, and check boundary of a given segment number */
  	if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg
-					|| segno > TOTAL_SEGS(sbi) - 1)) {
+					|| segno > MAIN_SEGS(sbi) - 1)) {
  		f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
  			 GET_SIT_VBLOCKS(raw_sit), segno);
  		set_sbi_flag(sbi, SBI_NEED_FSCK);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#2 lore raw
Quoted 6 lines · Chao Yu
Quoted 1 line · Jaegeuk Kim

MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.

Good catch!

Could you please add fixes line?

It seems this is not a bug case, and exisits from the first F2FS patch. :)

Quoted 28 lines

Thanks,

Quoted 25 lines
---
  fs/f2fs/segment.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/segment.h +2 -2
index 8ee5e5db9287..6003fbaf4b7d 100644
@@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
  static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
  {
-	f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
+	f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1);
  }
  static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)
@@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
  	/* check segment usage, and check boundary of a given segment number */
  	if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg
-					|| segno > TOTAL_SEGS(sbi) - 1)) {
+					|| segno > MAIN_SEGS(sbi) - 1)) {
  		f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
  			 GET_SIT_VBLOCKS(raw_sit), segno);
  		set_sbi_flag(sbi, SBI_NEED_FSCK);
author maintainer
#5 lore raw
In reply to Jaegeuk Kim

MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.

---

Change log from v1:
- replace check_seg_range with valid_main_segno to avoid confusion.

 fs/f2fs/segment.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/f2fs/segment.h +5 -4
index 92c8be00d396..efdb7fc3b797 100644
@@ -719,9 +719,10 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
 	return curseg->alloc_type;
 }
 
-static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
+static inline bool valid_main_segno(struct f2fs_sb_info *sbi,
+		unsigned int segno)
 {
-	f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
+	return segno <= (MAIN_SEGS(sbi) - 1);
 }
 
 static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)
@@ -776,7 +777,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
 
 	/* check segment usage, and check boundary of a given segment number */
 	if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg
-					|| segno > TOTAL_SEGS(sbi) - 1)) {
+					|| !valid_main_segno(sbi, segno))) {
 		f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
 			 GET_SIT_VBLOCKS(raw_sit), segno);
 		set_sbi_flag(sbi, SBI_NEED_FSCK);
@@ -793,7 +794,7 @@ static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi,
 	unsigned int offset = SIT_BLOCK_OFFSET(start);
 	block_t blk_addr = sit_i->sit_base_addr + offset;
 
-	check_seg_range(sbi, start);
+	f2fs_bug_on(sbi, !valid_main_segno(sbi, start));
 
 #ifdef CONFIG_F2FS_CHECK_FS
 	if (f2fs_test_bit(offset, sit_i->sit_bitmap) !=
Signature · 8 lines
2.39.1.581.gbfd45094c4-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer Reviewed-by
#3 lore raw
In reply to Jaegeuk Kim
Quoted 9 lines · Jaegeuk Kim
Quoted 6 lines · Chao Yu
Quoted 1 line · Jaegeuk Kim

MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.

Good catch!

Could you please add fixes line?

It seems this is not a bug case, and exisits from the first F2FS patch. :)

Alright, anyway, it looks good to me.

Thanks,

Quoted 29 lines
Quoted 29 lines

Thanks,

Quoted 25 lines
---
   fs/f2fs/segment.h | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/segment.h +2 -2
index 8ee5e5db9287..6003fbaf4b7d 100644
@@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
   static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
   {
-	f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
+	f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1);
   }
   static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)
@@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
   	/* check segment usage, and check boundary of a given segment number */
   	if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg
-					|| segno > TOTAL_SEGS(sbi) - 1)) {
+					|| segno > MAIN_SEGS(sbi) - 1)) {
   		f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
   			 GET_SIT_VBLOCKS(raw_sit), segno);
   		set_sbi_flag(sbi, SBI_NEED_FSCK);
author maintainer
#4 lore raw
Quoted 7 lines · Chao Yu
Quoted 6 lines · Jaegeuk Kim
Quoted 5 lines · Chao Yu
Quoted 1 line · Jaegeuk Kim

MAIN_SEGS is for data area, while TOTAL_SEGS includes data and metadata.

Good catch!

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Could you please add fixes line?

It seems this is not a bug case, and exisits from the first F2FS patch. :)

Alright, anyway, it looks good to me.

I assumed this for v2. Let me know if you have other concern.

Quoted 32 lines

Thanks,

Quoted 29 lines
Quoted 29 lines

Thanks,

Quoted 25 lines
---
   fs/f2fs/segment.h | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/segment.h +2 -2
index 8ee5e5db9287..6003fbaf4b7d 100644
@@ -720,7 +720,7 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi,
   static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
   {
-	f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
+	f2fs_bug_on(sbi, segno > MAIN_SEGS(sbi) - 1);
   }
   static inline void verify_fio_blkaddr(struct f2fs_io_info *fio)
@@ -775,7 +775,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
   	/* check segment usage, and check boundary of a given segment number */
   	if (unlikely(GET_SIT_VBLOCKS(raw_sit) > usable_blks_per_seg
-					|| segno > TOTAL_SEGS(sbi) - 1)) {
+					|| segno > MAIN_SEGS(sbi) - 1)) {
   		f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
   			 GET_SIT_VBLOCKS(raw_sit), segno);
   		set_sbi_flag(sbi, SBI_NEED_FSCK);