From: Chao Yu Date: Wed, 10 Jan 2018 10:18:51 +0000 (+0800) Subject: f2fs: fix to caclulate required free section correctly X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b9eedb48132e259fec06d6245783d759f3a972c3;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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: Chao Yu Signed-off-by: Jaegeuk Kim --- diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f7b7cd798558..3644a9027f5c 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2124,10 +2124,12 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, continue; } - if (blk_end && blk_end != map.m_pblk) { + if (blk_end && blk_end != map.m_pblk) 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; map.m_lblk += map.m_len; @@ -2136,10 +2138,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, if (!fragmented) goto out; - map.m_lblk = pg_start; - map.m_len = pg_end - pg_start; - - sec_num = (map.m_len + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi); + sec_num = (total + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi); /* * make sure there are enough free section for LFS allocation, this can @@ -2151,6 +2150,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, goto out; } + map.m_lblk = pg_start; + map.m_len = pg_end - pg_start; + total = 0; + while (map.m_lblk < pg_end) { pgoff_t idx; int cnt = 0;