f2fs: fix to release discard entries during checkpoint
authorChao Yu <yuchao0@huawei.com>
Tue, 11 Oct 2016 14:57:00 +0000 (22:57 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 23 Nov 2016 20:10:50 +0000 (12:10 -0800)
In f2fs_fill_super, if there is any IO error occurs during recovery,
cached discard entries will be leaked, in order to avoid this, make
write_checkpoint() handle memory release by itself, besides, move
clear_prefree_segments to write_checkpoint for readability.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c
fs/f2fs/super.c

index 7e9b504bd8b295787b22c8c933747894e42451d2..7db2aa2280ad8428c4f311c5a7177070002baf54 100644 (file)
@@ -1184,7 +1184,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        if (unlikely(f2fs_cp_error(sbi)))
                return -EIO;
 
-       clear_prefree_segments(sbi, cpc);
        clear_sbi_flag(sbi, SBI_IS_DIRTY);
        clear_sbi_flag(sbi, SBI_NEED_CP);
 
@@ -1261,8 +1260,12 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 
        /* unlock all the fs_lock[] in do_checkpoint() */
        err = do_checkpoint(sbi, cpc);
-
-       f2fs_wait_all_discard_bio(sbi);
+       if (err) {
+               release_discard_addrs(sbi);
+       } else {
+               clear_prefree_segments(sbi, cpc);
+               f2fs_wait_all_discard_bio(sbi);
+       }
 
        unblock_operations(sbi);
        stat_inc_cp_count(sbi->stat_info);
index 6132b4ce4e4ce348eec2c7c33ddce3700cb14b1b..bfa4414d707e798d2faacb18bcf74404e0d1df20 100644 (file)
@@ -738,7 +738,6 @@ static void f2fs_put_super(struct super_block *sb)
         * In addition, EIO will skip do checkpoint, we need this as well.
         */
        release_ino_entry(sbi, true);
-       release_discard_addrs(sbi);
 
        f2fs_leave_shrinker(sbi);
        mutex_unlock(&sbi->umount_mutex);