public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment
@ 2024-03-01  8:25 Zhiguo Niu
  2024-03-01  8:25 ` [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range Zhiguo Niu
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Zhiguo Niu @ 2024-03-01  8:25 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, zhiguo.niu, ke.wang,
	hongyu.jin

__allocate_new_segment may return error when get_new_segment
fails, so its caller should check its return value.

Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
 fs/f2fs/f2fs.h     | 2 +-
 fs/f2fs/recovery.c | 2 +-
 fs/f2fs/segment.c  | 7 +++++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index db05fd0..4331012 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3705,7 +3705,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
 					unsigned int start, unsigned int end);
 int f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force);
 int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi);
-void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
+int f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
 int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
 bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
 					struct cp_control *cpc);
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 3078d56..c381f0a 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -851,7 +851,7 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
 		f2fs_ra_meta_pages_cond(sbi, blkaddr, ra_blocks);
 	}
 	if (!err)
-		f2fs_allocate_new_segments(sbi);
+		err = f2fs_allocate_new_segments(sbi);
 	return err;
 }
 
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index cdac4cb..72f6ee3 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3163,16 +3163,19 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi)
 	return err;
 }
 
-void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
+int f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
 {
 	int i;
+	int err = 0;
 
 	f2fs_down_read(&SM_I(sbi)->curseg_lock);
 	down_write(&SIT_I(sbi)->sentry_lock);
 	for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++)
-		__allocate_new_segment(sbi, i, false, false);
+		err += __allocate_new_segment(sbi, i, false, false);
 	up_write(&SIT_I(sbi)->sentry_lock);
 	f2fs_up_read(&SM_I(sbi)->curseg_lock);
+
+	return err;
 }
 
 bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range
  2024-03-01  8:25 [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Zhiguo Niu
@ 2024-03-01  8:25 ` Zhiguo Niu
  2024-03-04  1:27   ` Chao Yu
  2024-03-04  1:25 ` [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Chao Yu
  2024-03-04 18:20 ` [f2fs-dev] " patchwork-bot+f2fs
  2 siblings, 1 reply; 5+ messages in thread
From: Zhiguo Niu @ 2024-03-01  8:25 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, zhiguo.niu, ke.wang,
	hongyu.jin

f2fs_gc_range may return error, so its caller
f2fs_allocate_pinning_section should determine whether
to do retry based on ist return value.

Also just do f2fs_gc_range when f2fs_allocate_new_section
return -EAGAIN, and check cp error case in f2fs_gc_range.

Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
 fs/f2fs/gc.c      |  3 +++
 fs/f2fs/segment.c | 13 ++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index e435e1f..c60b747 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -1986,6 +1986,9 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi,
 	unsigned int segno;
 	unsigned int gc_secs = dry_run_sections;
 
+	if (unlikely(f2fs_cp_error(sbi)))
+		return -EIO;
+
 	for (segno = start_seg; segno <= end_seg; segno += SEGS_PER_SEC(sbi)) {
 		struct gc_inode_list gc_list = {
 			.ilist = LIST_HEAD_INIT(gc_list.ilist),
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 72f6ee3..1bb3019 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3109,6 +3109,7 @@ static int __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
 {
 	struct curseg_info *curseg = CURSEG_I(sbi, type);
 	unsigned int old_segno;
+	int err = 0;
 
 	if (type == CURSEG_COLD_DATA_PINNED && !curseg->inited)
 		goto allocate;
@@ -3121,8 +3122,9 @@ static int __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
 
 allocate:
 	old_segno = curseg->segno;
-	if (new_curseg(sbi, type, true))
-		return -EAGAIN;
+	err = new_curseg(sbi, type, true);
+	if (err)
+		return err;
 	stat_inc_seg_type(sbi, curseg);
 	locate_dirty_segment(sbi, old_segno);
 	return 0;
@@ -3151,13 +3153,14 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi)
 	err = f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false);
 	f2fs_unlock_op(sbi);
 
-	if (f2fs_sb_has_blkzoned(sbi) && err && gc_required) {
+	if (f2fs_sb_has_blkzoned(sbi) && err == -EAGAIN && gc_required) {
 		f2fs_down_write(&sbi->gc_lock);
-		f2fs_gc_range(sbi, 0, GET_SEGNO(sbi, FDEV(0).end_blk), true, 1);
+		err = f2fs_gc_range(sbi, 0, GET_SEGNO(sbi, FDEV(0).end_blk), true, 1);
 		f2fs_up_write(&sbi->gc_lock);
 
 		gc_required = false;
-		goto retry;
+		if (!err)
+			goto retry;
 	}
 
 	return err;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment
  2024-03-01  8:25 [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Zhiguo Niu
  2024-03-01  8:25 ` [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range Zhiguo Niu
@ 2024-03-04  1:25 ` Chao Yu
  2024-03-04 18:20 ` [f2fs-dev] " patchwork-bot+f2fs
  2 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2024-03-04  1:25 UTC (permalink / raw)
  To: Zhiguo Niu, jaegeuk
  Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, ke.wang, hongyu.jin

On 2024/3/1 16:25, Zhiguo Niu wrote:
> __allocate_new_segment may return error when get_new_segment
> fails, so its caller should check its return value.
> 
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range
  2024-03-01  8:25 ` [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range Zhiguo Niu
@ 2024-03-04  1:27   ` Chao Yu
  0 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2024-03-04  1:27 UTC (permalink / raw)
  To: Zhiguo Niu, jaegeuk
  Cc: linux-f2fs-devel, linux-kernel, niuzhiguo84, ke.wang, hongyu.jin

On 2024/3/1 16:25, Zhiguo Niu wrote:
> f2fs_gc_range may return error, so its caller
> f2fs_allocate_pinning_section should determine whether
> to do retry based on ist return value.
> 
> Also just do f2fs_gc_range when f2fs_allocate_new_section
> return -EAGAIN, and check cp error case in f2fs_gc_range.
> 
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [f2fs-dev] [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment
  2024-03-01  8:25 [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Zhiguo Niu
  2024-03-01  8:25 ` [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range Zhiguo Niu
  2024-03-04  1:25 ` [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Chao Yu
@ 2024-03-04 18:20 ` patchwork-bot+f2fs
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+f2fs @ 2024-03-04 18:20 UTC (permalink / raw)
  To: Zhiguo Niu
  Cc: jaegeuk, chao, ke.wang, linux-kernel, linux-f2fs-devel,
	hongyu.jin

Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Fri, 1 Mar 2024 16:25:54 +0800 you wrote:
> __allocate_new_segment may return error when get_new_segment
> fails, so its caller should check its return value.
> 
> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
> ---
>  fs/f2fs/f2fs.h     | 2 +-
>  fs/f2fs/recovery.c | 2 +-
>  fs/f2fs/segment.c  | 7 +++++--
>  3 files changed, 7 insertions(+), 4 deletions(-)

Here is the summary with links:
  - [f2fs-dev,1/2] f2fs: fix to check return value __allocate_new_segment
    https://git.kernel.org/jaegeuk/f2fs/c/28f66cc65403
  - [f2fs-dev,2/2] f2fs: fix to check return value of f2fs_gc_range
    https://git.kernel.org/jaegeuk/f2fs/c/22af1b8c31cb

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-04 18:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-01  8:25 [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Zhiguo Niu
2024-03-01  8:25 ` [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range Zhiguo Niu
2024-03-04  1:27   ` Chao Yu
2024-03-04  1:25 ` [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Chao Yu
2024-03-04 18:20 ` [f2fs-dev] " patchwork-bot+f2fs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox