Skip to content

Commit e2cab03

Browse files
Sahitya TummalaJaegeuk Kim
authored andcommitted
f2fs: fix indefinite loop scanning for free nid
If the sbi->ckpt->next_free_nid is not NAT block aligned and if there are free nids in that NAT block between the start of the block and next_free_nid, then those free nids will not be scanned in scan_nat_page(). This results into mismatch between nm_i->available_nids and the sum of nm_i->free_nid_count of all NAT blocks scanned. And nm_i->available_nids will always be greater than the sum of free nids in all the blocks. Under this condition, if we use all the currently scanned free nids, then it will loop forever in f2fs_alloc_nid() as nm_i->available_nids is still not zero but nm_i->free_nid_count of that partially scanned NAT block is zero. Fix this to align the nm_i->next_scan_nid to the first nid of the corresponding NAT block. Signed-off-by: Sahitya Tummala <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 123aaf7 commit e2cab03

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/f2fs/node.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,9 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi,
23732373
if (unlikely(nid >= nm_i->max_nid))
23742374
nid = 0;
23752375

2376+
if (unlikely(nid % NAT_ENTRY_PER_BLOCK))
2377+
nid = NAT_BLOCK_OFFSET(nid) * NAT_ENTRY_PER_BLOCK;
2378+
23762379
/* Enough entries */
23772380
if (nm_i->nid_cnt[FREE_NID] >= NAT_ENTRY_PER_BLOCK)
23782381
return 0;

0 commit comments

Comments
 (0)