resize.f2fs: fix wrong nat_bits migration
authorJaegeuk Kim <jaegeuk@kernel.org>
Sun, 17 Jun 2018 00:09:23 +0000 (17:09 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 29 Jun 2018 02:21:49 +0000 (19:21 -0700)
When wring the last nat_bits in new checkpoint, we call write_nat_bits()
to recover the nat_bits. But, we didn't update nm_i->nat_bitmap which we can
get the up-to-date nat blocks. After sit migration, old checkpoint has no
longer valid nat blocks, resulting in wrong free nid allocation at the following
mount time.

Let's indicate new nat_blocks by adjusting nat_bitmap in nat migration.

Reported-by: Lianjun Huang <huanglianjun@vivo.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/resize.c

index 7643511..b2adf3e 100644 (file)
@@ -339,8 +339,11 @@ static void migrate_nat(struct f2fs_sb_info *sbi,
                                (seg_off << sbi->log_blocks_per_seg << 1) +
                                (block_off & ((1 << sbi->log_blocks_per_seg) - 1)));
 
-               if (f2fs_test_bit(block_off, nm_i->nat_bitmap))
+               /* move to set #0 */
+               if (f2fs_test_bit(block_off, nm_i->nat_bitmap)) {
                        block_addr += sbi->blocks_per_seg;
+                       f2fs_clear_bit(block_off, nm_i->nat_bitmap);
+               }
 
                ret = dev_read_block(nat_block, block_addr);
                ASSERT(ret >= 0);