Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 862cf9f2 authored by Zhiguo Niu's avatar Zhiguo Niu Committed by Daniel Rosenberg
Browse files

BACKPORT: f2fs: stop checkpoint when get a out-of-bounds segment



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

Note, f2fs_stop_checkpoint(, false) is complex and it may sleep, so we should
move it outside segmap_lock spinlock coverage in get_new_segment().

Signed-off-by: default avatarZhiguo Niu <zhiguo.niu@unisoc.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>

(cherry picked from commit f9e28904e6442019043a8e94ec6747a064d06003)
[drosen: Fixed conflict in segment.c, applying logic to both branches,
         removed stop_cp_reason as it doesn't exist in 4.19]
Change-Id: I6f9eaa87c76dcab319f3351cb2ffae701eaa3332
Signed-off-by: default avatarDaniel Rosenberg <drosen@google.com>
Bug: 358293777
parent d7575523
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -2394,6 +2394,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
	bool init = true;
	int go_left = 0;
	int i;
	int ret = 0;

	spin_lock(&free_i->segmap_lock);

@@ -2409,7 +2410,10 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
		if (dir == ALLOC_RIGHT) {
			secno = find_next_zero_bit(free_i->free_secmap,
							MAIN_SECS(sbi), 0);
			f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi));
			if (secno >= MAIN_SECS(sbi)) {
				ret = -ENOSPC;
				goto out_unlock;
			}
		} else {
			go_left = 1;
			left_start = hint - 1;
@@ -2425,7 +2429,10 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
		}
		left_start = find_next_zero_bit(free_i->free_secmap,
							MAIN_SECS(sbi), 0);
		f2fs_bug_on(sbi, left_start >= MAIN_SECS(sbi));
		if (left_start >= MAIN_SECS(sbi)) {
			ret = -ENOSPC;
			goto out_unlock;
		}
		break;
	}
	secno = left_start;
@@ -2466,7 +2473,13 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
	f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
	__set_inuse(sbi, segno);
	*newseg = segno;
out_unlock:
	spin_unlock(&free_i->segmap_lock);

	if (ret) {
		f2fs_stop_checkpoint(sbi, false);
		f2fs_bug_on(sbi, 1);
	}
}

static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)