Re: [f2fs-dev] [PATCH v2 4/4] f2fs: stop checkpoint when get a out-of-bounds segment

2024-02-18 Thread Chao Yu

On 2024/2/8 8:16, Jaegeuk Kim wrote:

On 02/07, Zhiguo Niu wrote:

There is low probability that an out-of-bounds segment will be got
on a small-capacity device. In order to prevent subsequent write requests
allocating block address from this invalid segment, which may cause
unexpected issue, stop checkpoint should be performed.

Also introduce a new stop cp reason:  STOP_CP_REASON_OUTOF_RAGNE.


OUT_OF_RANGE?


Maybe STOP_CP_REASON_NO_SEGMENT will be more explicit?

Thanks,





Signed-off-by: Zhiguo Niu 
---
  fs/f2fs/segment.c   | 12 ++--
  include/linux/f2fs_fs.h |  1 +
  2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 6772ad4..6fe2baf 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2666,7 +2666,11 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
if (dir == ALLOC_RIGHT) {
secno = find_first_zero_bit(free_i->free_secmap,
MAIN_SECS(sbi));
-   f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi));
+   if (secno >= MAIN_SECS(sbi)) {
+   f2fs_stop_checkpoint(sbi, false,
+   STOP_CP_REASON_OUTOF_RAGNE);
+   f2fs_bug_on(sbi, 1);
+   }
} else {
go_left = 1;
left_start = hint - 1;
@@ -2682,7 +2686,11 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
}
left_start = find_first_zero_bit(free_i->free_secmap,
MAIN_SECS(sbi));
-   f2fs_bug_on(sbi, left_start >= MAIN_SECS(sbi));
+   if (left_start >= MAIN_SECS(sbi)) {
+   f2fs_stop_checkpoint(sbi, false,
+   STOP_CP_REASON_OUTOF_RAGNE);
+   f2fs_bug_on(sbi, 1);
+   }
break;
}
secno = left_start;
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 053137a0..72c6782 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -81,6 +81,7 @@ enum stop_cp_reason {
STOP_CP_REASON_CORRUPTED_SUMMARY,
STOP_CP_REASON_UPDATE_INODE,
STOP_CP_REASON_FLUSH_FAIL,
+   STOP_CP_REASON_OUTOF_RAGNE,
STOP_CP_REASON_MAX,
  };
  
--

1.9.1



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH v2 4/4] f2fs: stop checkpoint when get a out-of-bounds segment

2024-02-07 Thread Jaegeuk Kim
On 02/07, Zhiguo Niu wrote:
> There is low probability that an out-of-bounds segment will be got
> on a small-capacity device. In order to prevent subsequent write requests
> allocating block address from this invalid segment, which may cause
> unexpected issue, stop checkpoint should be performed.
> 
> Also introduce a new stop cp reason:  STOP_CP_REASON_OUTOF_RAGNE.

OUT_OF_RANGE?

> 
> Signed-off-by: Zhiguo Niu 
> ---
>  fs/f2fs/segment.c   | 12 ++--
>  include/linux/f2fs_fs.h |  1 +
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 6772ad4..6fe2baf 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2666,7 +2666,11 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
>   if (dir == ALLOC_RIGHT) {
>   secno = find_first_zero_bit(free_i->free_secmap,
>   MAIN_SECS(sbi));
> - f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi));
> + if (secno >= MAIN_SECS(sbi)) {
> + f2fs_stop_checkpoint(sbi, false,
> + STOP_CP_REASON_OUTOF_RAGNE);
> + f2fs_bug_on(sbi, 1);
> + }
>   } else {
>   go_left = 1;
>   left_start = hint - 1;
> @@ -2682,7 +2686,11 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
>   }
>   left_start = find_first_zero_bit(free_i->free_secmap,
>   MAIN_SECS(sbi));
> - f2fs_bug_on(sbi, left_start >= MAIN_SECS(sbi));
> + if (left_start >= MAIN_SECS(sbi)) {
> + f2fs_stop_checkpoint(sbi, false,
> + STOP_CP_REASON_OUTOF_RAGNE);
> + f2fs_bug_on(sbi, 1);
> + }
>   break;
>   }
>   secno = left_start;
> diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
> index 053137a0..72c6782 100644
> --- a/include/linux/f2fs_fs.h
> +++ b/include/linux/f2fs_fs.h
> @@ -81,6 +81,7 @@ enum stop_cp_reason {
>   STOP_CP_REASON_CORRUPTED_SUMMARY,
>   STOP_CP_REASON_UPDATE_INODE,
>   STOP_CP_REASON_FLUSH_FAIL,
> + STOP_CP_REASON_OUTOF_RAGNE,
>   STOP_CP_REASON_MAX,
>  };
>  
> -- 
> 1.9.1


___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel