aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2013-01-29 05:14:48 -0500
committerJosef Bacik <jbacik@fusionio.com>2013-02-20 12:59:09 -0500
commit87533c475187c1420794a2e164bc67a7974f1327 (patch)
tree699709da85c0a6c284cf37fe7026fbaf4768e6ab /fs/btrfs/disk-io.c
parentde98ced9e743656d108de41841797def0f5cb951 (diff)
Btrfs: use bit operation for ->fs_state
There is no lock to protect fs_info->fs_state, it will introduce some problems, such as the value may be covered by the other task when several tasks modify it. For example: Task0 - CPU0 Task1 - CPU1 mov %fs_state rax or $0x1 rax mov %fs_state rax or $0x2 rax mov rax %fs_state mov rax %fs_state The expected value is 3, but in fact, it is 2. Though this problem doesn't happen now (because there is only one flag currently), the code is error prone, if we add other flags, the above problem will happen to a certainty. Now we use bit operation for it to fix the above problem. In this way, we can make the code more robust and be easy to add new flags. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 00b6742fdde7..8e58a1f90546 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2201,7 +2201,8 @@ int open_ctree(struct super_block *sb,
2201 goto fail_alloc; 2201 goto fail_alloc;
2202 2202
2203 /* check FS state, whether FS is broken. */ 2203 /* check FS state, whether FS is broken. */
2204 fs_info->fs_state |= btrfs_super_flags(disk_super); 2204 if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_ERROR)
2205 set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
2205 2206
2206 ret = btrfs_check_super_valid(fs_info, sb->s_flags & MS_RDONLY); 2207 ret = btrfs_check_super_valid(fs_info, sb->s_flags & MS_RDONLY);
2207 if (ret) { 2208 if (ret) {
@@ -3359,7 +3360,7 @@ int close_ctree(struct btrfs_root *root)
3359 printk(KERN_ERR "btrfs: commit super ret %d\n", ret); 3360 printk(KERN_ERR "btrfs: commit super ret %d\n", ret);
3360 } 3361 }
3361 3362
3362 if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) 3363 if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
3363 btrfs_error_commit_super(root); 3364 btrfs_error_commit_super(root);
3364 3365
3365 btrfs_put_block_group_cache(fs_info); 3366 btrfs_put_block_group_cache(fs_info);