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>
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user