summaryrefslogtreecommitdiff
authorChao Yu <yuchao0@huawei.com>2019-05-05 03:40:46 (GMT)
committer Jaegeuk Kim <jaegeuk@kernel.org>2019-05-09 04:47:06 (GMT)
commitbe1955f7a7674cd61e84d1caa19f717f1555355c (patch)
tree1793a9255556a03ec345d1d7a73c0e1fcaad6790
parentde69ac794f7e3e57f67c3f814f30e00bf48b99c9 (diff)
downloadcommon-be1955f7a7674cd61e84d1caa19f717f1555355c.zip
common-be1955f7a7674cd61e84d1caa19f717f1555355c.tar.gz
common-be1955f7a7674cd61e84d1caa19f717f1555355c.tar.bz2
f2fs: fix to avoid potential race on sbi->unusable_block_count access/update
Use sbi.stat_lock to protect sbi->unusable_block_count accesss/udpate, in order to avoid potential race on it. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat
-rw-r--r--fs/f2fs/checkpoint.c4
-rw-r--r--fs/f2fs/segment.c5
-rw-r--r--fs/f2fs/super.c6
3 files changed, 14 insertions, 1 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index aa91657..d4c5310 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1536,7 +1536,11 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
clear_sbi_flag(sbi, SBI_IS_DIRTY);
clear_sbi_flag(sbi, SBI_NEED_CP);
clear_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
+
+ spin_lock(&sbi->stat_lock);
sbi->unusable_block_count = 0;
+ spin_unlock(&sbi->stat_lock);
+
__set_cp_next_pack(sbi);
/*
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index e708932..2a8dc33 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2165,8 +2165,11 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
* before, we must track that to know how much space we
* really have.
*/
- if (f2fs_test_bit(offset, se->ckpt_valid_map))
+ if (f2fs_test_bit(offset, se->ckpt_valid_map)) {
+ spin_lock(&sbi->stat_lock);
sbi->unusable_block_count++;
+ spin_unlock(&sbi->stat_lock);
+ }
}
if (f2fs_test_and_clear_bit(offset, se->discard_map))
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index cc2e756..a6de02a 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1226,10 +1226,13 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
buf->f_blocks = total_count - start_count;
buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
sbi->current_reserved_blocks;
+
+ spin_lock(&sbi->stat_lock);
if (unlikely(buf->f_bfree <= sbi->unusable_block_count))
buf->f_bfree = 0;
else
buf->f_bfree -= sbi->unusable_block_count;
+ spin_unlock(&sbi->stat_lock);
if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
buf->f_bavail = buf->f_bfree -
@@ -1508,7 +1511,10 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi)
if (err)
goto out_unlock;
+ spin_lock(&sbi->stat_lock);
sbi->unusable_block_count = 0;
+ spin_unlock(&sbi->stat_lock);
+
out_unlock:
mutex_unlock(&sbi->gc_mutex);
restore_flag: