diff options
author | Chao Yu <yuchao0@huawei.com> | 2019-05-04 23:40:46 -0400 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-05-09 00:23:13 -0400 |
commit | c9c8ed50d94c613fc3f4917c51e9c75d493a312e (patch) | |
tree | 161bfa38f995f3fceae4c60d4d9ba1f85384a7f2 | |
parent | d764834378a9870ca56e9b2977ea46e9911ec358 (diff) |
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>
-rw-r--r-- | fs/f2fs/checkpoint.c | 4 | ||||
-rw-r--r-- | fs/f2fs/segment.c | 5 | ||||
-rw-r--r-- | fs/f2fs/super.c | 6 |
3 files changed, 14 insertions, 1 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 805a33088e82..ed70b68b2b38 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) | |||
1536 | clear_sbi_flag(sbi, SBI_IS_DIRTY); | 1536 | clear_sbi_flag(sbi, SBI_IS_DIRTY); |
1537 | clear_sbi_flag(sbi, SBI_NEED_CP); | 1537 | clear_sbi_flag(sbi, SBI_NEED_CP); |
1538 | clear_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH); | 1538 | clear_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH); |
1539 | |||
1540 | spin_lock(&sbi->stat_lock); | ||
1539 | sbi->unusable_block_count = 0; | 1541 | sbi->unusable_block_count = 0; |
1542 | spin_unlock(&sbi->stat_lock); | ||
1543 | |||
1540 | __set_cp_next_pack(sbi); | 1544 | __set_cp_next_pack(sbi); |
1541 | 1545 | ||
1542 | /* | 1546 | /* |
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 8388d2abacb5..8dee063c833f 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c | |||
@@ -2169,8 +2169,11 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) | |||
2169 | * before, we must track that to know how much space we | 2169 | * before, we must track that to know how much space we |
2170 | * really have. | 2170 | * really have. |
2171 | */ | 2171 | */ |
2172 | if (f2fs_test_bit(offset, se->ckpt_valid_map)) | 2172 | if (f2fs_test_bit(offset, se->ckpt_valid_map)) { |
2173 | spin_lock(&sbi->stat_lock); | ||
2173 | sbi->unusable_block_count++; | 2174 | sbi->unusable_block_count++; |
2175 | spin_unlock(&sbi->stat_lock); | ||
2176 | } | ||
2174 | } | 2177 | } |
2175 | 2178 | ||
2176 | if (f2fs_test_and_clear_bit(offset, se->discard_map)) | 2179 | if (f2fs_test_and_clear_bit(offset, se->discard_map)) |
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index fe075aa12893..7ddf0d3cbece 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) | |||
1226 | buf->f_blocks = total_count - start_count; | 1226 | buf->f_blocks = total_count - start_count; |
1227 | buf->f_bfree = user_block_count - valid_user_blocks(sbi) - | 1227 | buf->f_bfree = user_block_count - valid_user_blocks(sbi) - |
1228 | sbi->current_reserved_blocks; | 1228 | sbi->current_reserved_blocks; |
1229 | |||
1230 | spin_lock(&sbi->stat_lock); | ||
1229 | if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) | 1231 | if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) |
1230 | buf->f_bfree = 0; | 1232 | buf->f_bfree = 0; |
1231 | else | 1233 | else |
1232 | buf->f_bfree -= sbi->unusable_block_count; | 1234 | buf->f_bfree -= sbi->unusable_block_count; |
1235 | spin_unlock(&sbi->stat_lock); | ||
1233 | 1236 | ||
1234 | if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) | 1237 | if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) |
1235 | buf->f_bavail = buf->f_bfree - | 1238 | buf->f_bavail = buf->f_bfree - |
@@ -1508,7 +1511,10 @@ static int f2fs_disable_checkpoint(struct f2fs_sb_info *sbi) | |||
1508 | if (err) | 1511 | if (err) |
1509 | goto out_unlock; | 1512 | goto out_unlock; |
1510 | 1513 | ||
1514 | spin_lock(&sbi->stat_lock); | ||
1511 | sbi->unusable_block_count = 0; | 1515 | sbi->unusable_block_count = 0; |
1516 | spin_unlock(&sbi->stat_lock); | ||
1517 | |||
1512 | out_unlock: | 1518 | out_unlock: |
1513 | mutex_unlock(&sbi->gc_mutex); | 1519 | mutex_unlock(&sbi->gc_mutex); |
1514 | restore_flag: | 1520 | restore_flag: |