提交 d3a1a0e1 编写于 作者: C Chao Yu 提交者: Jaegeuk Kim

f2fs: fix to migrate blocks correctly during defragment

During defragment, we missed to trigger fragmented blocks migration
for below condition:

In defragment region:
- total number of valid blocks is smaller than 512;
- the tail part of the region are all holes;

In addtion, return zero to user via range->len if there is no
fragmented blocks.
Signed-off-by: NChao Yu <yuchao0@huawei.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 33ac18a1
...@@ -2383,8 +2383,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -2383,8 +2383,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
map.m_lblk += map.m_len; map.m_lblk += map.m_len;
} }
if (!fragmented) if (!fragmented) {
total = 0;
goto out; goto out;
}
sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi)); sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi));
...@@ -2414,7 +2416,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -2414,7 +2416,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
if (!(map.m_flags & F2FS_MAP_FLAGS)) { if (!(map.m_flags & F2FS_MAP_FLAGS)) {
map.m_lblk = next_pgofs; map.m_lblk = next_pgofs;
continue; goto check;
} }
set_inode_flag(inode, FI_DO_DEFRAG); set_inode_flag(inode, FI_DO_DEFRAG);
...@@ -2438,8 +2440,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -2438,8 +2440,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
} }
map.m_lblk = idx; map.m_lblk = idx;
check:
if (idx < pg_end && cnt < blk_per_seg) if (map.m_lblk < pg_end && cnt < blk_per_seg)
goto do_map; goto do_map;
clear_inode_flag(inode, FI_DO_DEFRAG); clear_inode_flag(inode, FI_DO_DEFRAG);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册