]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: fix to update f2fs_super_block fields under sb_lock
authorChao Yu <yuchao0@huawei.com>
Tue, 3 Mar 2020 12:09:25 +0000 (20:09 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 23 Mar 2020 04:16:29 +0000 (21:16 -0700)
Fields in struct f2fs_super_block should be updated under coverage
of sb_lock, fix to adjust update_sb_metadata() for that rule.

Fixes: 04f0b2eaa3b3 ("f2fs: ioctl for removing a range from F2FS")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/gc.c

index bc203e24a039235f0f075362af25bb640295ed1e..f122fe3dbba3bcde069cc9ed245938343d13374a 100644 (file)
@@ -1442,12 +1442,19 @@ static int free_segment_range(struct f2fs_sb_info *sbi, unsigned int start,
 static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs)
 {
        struct f2fs_super_block *raw_sb = F2FS_RAW_SUPER(sbi);
-       int section_count = le32_to_cpu(raw_sb->section_count);
-       int segment_count = le32_to_cpu(raw_sb->segment_count);
-       int segment_count_main = le32_to_cpu(raw_sb->segment_count_main);
-       long long block_count = le64_to_cpu(raw_sb->block_count);
+       int section_count;
+       int segment_count;
+       int segment_count_main;
+       long long block_count;
        int segs = secs * sbi->segs_per_sec;
 
+       down_write(&sbi->sb_lock);
+
+       section_count = le32_to_cpu(raw_sb->section_count);
+       segment_count = le32_to_cpu(raw_sb->segment_count);
+       segment_count_main = le32_to_cpu(raw_sb->segment_count_main);
+       block_count = le64_to_cpu(raw_sb->block_count);
+
        raw_sb->section_count = cpu_to_le32(section_count + secs);
        raw_sb->segment_count = cpu_to_le32(segment_count + segs);
        raw_sb->segment_count_main = cpu_to_le32(segment_count_main + segs);
@@ -1461,6 +1468,8 @@ static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs)
                raw_sb->devs[last_dev].total_segments =
                                                cpu_to_le32(dev_segs + segs);
        }
+
+       up_write(&sbi->sb_lock);
 }
 
 static void update_fs_metadata(struct f2fs_sb_info *sbi, int secs)