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

f2fs: fix to caclulate required free section correctly

When calculating required free section during file defragmenting, we
should skip holes in file, otherwise we will probably fail to defrag
sparse file with large size.
Signed-off-by: NChao Yu <yuchao0@huawei.com>
Signed-off-by: NJaegeuk Kim <jaegeuk@kernel.org>
上级 f1d2564a
...@@ -2125,10 +2125,12 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -2125,10 +2125,12 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
continue; continue;
} }
if (blk_end && blk_end != map.m_pblk) { if (blk_end && blk_end != map.m_pblk)
fragmented = true; fragmented = true;
break;
} /* record total count of block that we're going to move */
total += map.m_len;
blk_end = map.m_pblk + map.m_len; blk_end = map.m_pblk + map.m_len;
map.m_lblk += map.m_len; map.m_lblk += map.m_len;
...@@ -2137,10 +2139,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -2137,10 +2139,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
if (!fragmented) if (!fragmented)
goto out; goto out;
map.m_lblk = pg_start; sec_num = (total + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi);
map.m_len = pg_end - pg_start;
sec_num = (map.m_len + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi);
/* /*
* make sure there are enough free section for LFS allocation, this can * make sure there are enough free section for LFS allocation, this can
...@@ -2152,6 +2151,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -2152,6 +2151,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
goto out; goto out;
} }
map.m_lblk = pg_start;
map.m_len = pg_end - pg_start;
total = 0;
while (map.m_lblk < pg_end) { while (map.m_lblk < pg_end) {
pgoff_t idx; pgoff_t idx;
int cnt = 0; int cnt = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册