mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
UPSTREAM: f2fs: clean up zones when not successfully unmounted
We can't trust write pointers when the previous mount was not successfully unmounted. Change-Id: If67696db9ab820a805711b43cabb50c796c9f75f Signed-off-by: Daeho Jeong <daehojeong@google.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> (cherry picked from commit 9f792ab8e33de727993bbd84ece892e72de18c85)
This commit is contained in:
@@ -4813,22 +4813,31 @@ static int check_zone_write_pointer(struct f2fs_sb_info *sbi,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The write pointer matches with the valid blocks or
|
* When safely unmounted in the previous mount, we can trust write
|
||||||
* already points to the end of the zone.
|
* pointers. Otherwise, finish zones.
|
||||||
*/
|
*/
|
||||||
if ((last_valid_block + 1 == wp_block) ||
|
if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
|
||||||
(zone->wp == zone->start + zone->len))
|
/*
|
||||||
return 0;
|
* The write pointer matches with the valid blocks or
|
||||||
|
* already points to the end of the zone.
|
||||||
|
*/
|
||||||
|
if ((last_valid_block + 1 == wp_block) ||
|
||||||
|
(zone->wp == zone->start + zone->len))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (last_valid_block + 1 == zone_block) {
|
if (last_valid_block + 1 == zone_block) {
|
||||||
/*
|
if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
|
||||||
* If there is no valid block in the zone and if write pointer
|
/*
|
||||||
* is not at zone start, reset the write pointer.
|
* If there is no valid block in the zone and if write
|
||||||
*/
|
* pointer is not at zone start, reset the write
|
||||||
f2fs_notice(sbi,
|
* pointer.
|
||||||
"Zone without valid block has non-zero write "
|
*/
|
||||||
"pointer. Reset the write pointer: wp[0x%x,0x%x]",
|
f2fs_notice(sbi,
|
||||||
wp_segno, wp_blkoff);
|
"Zone without valid block has non-zero write "
|
||||||
|
"pointer. Reset the write pointer: wp[0x%x,0x%x]",
|
||||||
|
wp_segno, wp_blkoff);
|
||||||
|
}
|
||||||
ret = __f2fs_issue_discard_zone(sbi, fdev->bdev, zone_block,
|
ret = __f2fs_issue_discard_zone(sbi, fdev->bdev, zone_block,
|
||||||
zone->len >> log_sectors_per_block);
|
zone->len >> log_sectors_per_block);
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -4838,18 +4847,20 @@ static int check_zone_write_pointer(struct f2fs_sb_info *sbi,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
|
||||||
* If there are valid blocks and the write pointer doesn't
|
/*
|
||||||
* match with them, we need to report the inconsistency and
|
* If there are valid blocks and the write pointer doesn't match
|
||||||
* fill the zone till the end to close the zone. This inconsistency
|
* with them, we need to report the inconsistency and fill
|
||||||
* does not cause write error because the zone will not be selected
|
* the zone till the end to close the zone. This inconsistency
|
||||||
* for write operation until it get discarded.
|
* does not cause write error because the zone will not be
|
||||||
*/
|
* selected for write operation until it get discarded.
|
||||||
f2fs_notice(sbi, "Valid blocks are not aligned with write pointer: "
|
*/
|
||||||
"valid block[0x%x,0x%x] wp[0x%x,0x%x]",
|
f2fs_notice(sbi, "Valid blocks are not aligned with write "
|
||||||
GET_SEGNO(sbi, last_valid_block),
|
"pointer: valid block[0x%x,0x%x] wp[0x%x,0x%x]",
|
||||||
GET_BLKOFF_FROM_SEG0(sbi, last_valid_block),
|
GET_SEGNO(sbi, last_valid_block),
|
||||||
wp_segno, wp_blkoff);
|
GET_BLKOFF_FROM_SEG0(sbi, last_valid_block),
|
||||||
|
wp_segno, wp_blkoff);
|
||||||
|
}
|
||||||
|
|
||||||
ret = blkdev_zone_mgmt(fdev->bdev, REQ_OP_ZONE_FINISH,
|
ret = blkdev_zone_mgmt(fdev->bdev, REQ_OP_ZONE_FINISH,
|
||||||
zone->start, zone->len, GFP_NOFS);
|
zone->start, zone->len, GFP_NOFS);
|
||||||
@@ -4923,18 +4934,27 @@ static int fix_curseg_write_pointer(struct f2fs_sb_info *sbi, int type)
|
|||||||
if (zone.type != BLK_ZONE_TYPE_SEQWRITE_REQ)
|
if (zone.type != BLK_ZONE_TYPE_SEQWRITE_REQ)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
wp_block = zbd->start_blk + (zone.wp >> log_sectors_per_block);
|
/*
|
||||||
wp_segno = GET_SEGNO(sbi, wp_block);
|
* When safely unmounted in the previous mount, we could use current
|
||||||
wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno);
|
* segments. Otherwise, allocate new sections.
|
||||||
wp_sector_off = zone.wp & GENMASK(log_sectors_per_block - 1, 0);
|
*/
|
||||||
|
if (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
|
||||||
|
wp_block = zbd->start_blk + (zone.wp >> log_sectors_per_block);
|
||||||
|
wp_segno = GET_SEGNO(sbi, wp_block);
|
||||||
|
wp_blkoff = wp_block - START_BLOCK(sbi, wp_segno);
|
||||||
|
wp_sector_off = zone.wp & GENMASK(log_sectors_per_block - 1, 0);
|
||||||
|
|
||||||
if (cs->segno == wp_segno && cs->next_blkoff == wp_blkoff &&
|
if (cs->segno == wp_segno && cs->next_blkoff == wp_blkoff &&
|
||||||
wp_sector_off == 0)
|
wp_sector_off == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
f2fs_notice(sbi, "Unaligned curseg[%d] with write pointer: "
|
f2fs_notice(sbi, "Unaligned curseg[%d] with write pointer: "
|
||||||
"curseg[0x%x,0x%x] wp[0x%x,0x%x]",
|
"curseg[0x%x,0x%x] wp[0x%x,0x%x]", type, cs->segno,
|
||||||
type, cs->segno, cs->next_blkoff, wp_segno, wp_blkoff);
|
cs->next_blkoff, wp_segno, wp_blkoff);
|
||||||
|
} else {
|
||||||
|
f2fs_notice(sbi, "Not successfully unmounted in the previous "
|
||||||
|
"mount");
|
||||||
|
}
|
||||||
|
|
||||||
f2fs_notice(sbi, "Assign new section to curseg[%d]: "
|
f2fs_notice(sbi, "Assign new section to curseg[%d]: "
|
||||||
"curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
|
"curseg[0x%x,0x%x]", type, cs->segno, cs->next_blkoff);
|
||||||
|
|||||||
Reference in New Issue
Block a user