mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
UPSTREAM: 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: Zhiguo Niu <zhiguo.niu@unisoc.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Change-Id: Ie5a83b05851a0b5c0c75fa74dbcf9261065724fa Bug: 361829529 (cherry picked from commit f9e28904e6442019043a8e94ec6747a064d06003) Signed-off-by: Daeho Jeong <daehojeong@google.com>
This commit is contained in:
@@ -2561,6 +2561,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi,
|
|||||||
unsigned int old_zoneno = GET_ZONE_FROM_SEG(sbi, *newseg);
|
unsigned int old_zoneno = GET_ZONE_FROM_SEG(sbi, *newseg);
|
||||||
bool init = true;
|
bool init = true;
|
||||||
int i;
|
int i;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
spin_lock(&free_i->segmap_lock);
|
spin_lock(&free_i->segmap_lock);
|
||||||
|
|
||||||
@@ -2575,7 +2576,10 @@ find_other_zone:
|
|||||||
if (secno >= MAIN_SECS(sbi)) {
|
if (secno >= MAIN_SECS(sbi)) {
|
||||||
secno = find_first_zero_bit(free_i->free_secmap,
|
secno = find_first_zero_bit(free_i->free_secmap,
|
||||||
MAIN_SECS(sbi));
|
MAIN_SECS(sbi));
|
||||||
f2fs_bug_on(sbi, secno >= MAIN_SECS(sbi));
|
if (secno >= MAIN_SECS(sbi)) {
|
||||||
|
ret = -ENOSPC;
|
||||||
|
goto out_unlock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
segno = GET_SEG_FROM_SEC(sbi, secno);
|
segno = GET_SEG_FROM_SEC(sbi, secno);
|
||||||
zoneno = GET_ZONE_FROM_SEC(sbi, secno);
|
zoneno = GET_ZONE_FROM_SEC(sbi, secno);
|
||||||
@@ -2605,7 +2609,13 @@ got_it:
|
|||||||
f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
|
f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
|
||||||
__set_inuse(sbi, segno);
|
__set_inuse(sbi, segno);
|
||||||
*newseg = segno;
|
*newseg = segno;
|
||||||
|
out_unlock:
|
||||||
spin_unlock(&free_i->segmap_lock);
|
spin_unlock(&free_i->segmap_lock);
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT);
|
||||||
|
f2fs_bug_on(sbi, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)
|
static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ enum stop_cp_reason {
|
|||||||
STOP_CP_REASON_CORRUPTED_SUMMARY,
|
STOP_CP_REASON_CORRUPTED_SUMMARY,
|
||||||
STOP_CP_REASON_UPDATE_INODE,
|
STOP_CP_REASON_UPDATE_INODE,
|
||||||
STOP_CP_REASON_FLUSH_FAIL,
|
STOP_CP_REASON_FLUSH_FAIL,
|
||||||
|
STOP_CP_REASON_NO_SEGMENT,
|
||||||
STOP_CP_REASON_MAX,
|
STOP_CP_REASON_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user