struct curseg_info *curseg = CURSEG_I(sbi, type);
unsigned int old_segno;
+ if (type == CURSEG_COLD_DATA_PINNED && !curseg->inited)
+ goto allocate;
+
if (!force && curseg->inited &&
!curseg->next_blkoff &&
!get_valid_blocks(sbi, curseg->segno, new_sec) &&
!get_ckpt_valid_blocks(sbi, curseg->segno, new_sec))
return 0;
+allocate:
old_segno = curseg->segno;
if (new_curseg(sbi, type, true))
return -EAGAIN;
get_random_u32_inclusive(1, sbi->max_fragment_hole);
}
+static void reset_curseg_fields(struct curseg_info *curseg)
+{
+ curseg->inited = false;
+ curseg->segno = NULL_SEGNO;
+ curseg->next_segno = 0;
+}
+
int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
block_t old_blkaddr, block_t *new_blkaddr,
struct f2fs_summary *sum, int type,
*/
if (segment_full) {
if (type == CURSEG_COLD_DATA_PINNED &&
- !((curseg->segno + 1) % sbi->segs_per_sec))
+ !((curseg->segno + 1) % sbi->segs_per_sec)) {
+ reset_curseg_fields(curseg);
goto skip_new_segment;
+ }
if (from_gc) {
get_atssr_segment(sbi, type, se->type,
array[i].seg_type = CURSEG_COLD_DATA;
else if (i == CURSEG_ALL_DATA_ATGC)
array[i].seg_type = CURSEG_COLD_DATA;
- array[i].segno = NULL_SEGNO;
- array[i].next_blkoff = 0;
- array[i].inited = false;
+ reset_curseg_fields(&array[i]);
}
return restore_curseg_summaries(sbi);
}