aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2013-01-29 05:13:12 -0500
committerJosef Bacik <jbacik@fusionio.com>2013-02-20 12:59:08 -0500
commitde98ced9e743656d108de41841797def0f5cb951 (patch)
tree52314be4abe2cd2510712e8b629d58d8d01d5e0a /fs/btrfs/extent-tree.c
parentdf0af1a57f72c74d53a9377c60ff20095afab97d (diff)
Btrfs: use seqlock to protect fs_info->avail_{data, metadata, system}_alloc_bits
There is no lock to protect fs_info->avail_{data, metadata, system}_alloc_bits, it may introduce some problem, such as the wrong profile information, so we add a seqlock to protect them. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 115d1646bf50..faff98f720de 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3227,12 +3227,14 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
3227 u64 extra_flags = chunk_to_extended(flags) & 3227 u64 extra_flags = chunk_to_extended(flags) &
3228 BTRFS_EXTENDED_PROFILE_MASK; 3228 BTRFS_EXTENDED_PROFILE_MASK;
3229 3229
3230 write_seqlock(&fs_info->profiles_lock);
3230 if (flags & BTRFS_BLOCK_GROUP_DATA) 3231 if (flags & BTRFS_BLOCK_GROUP_DATA)
3231 fs_info->avail_data_alloc_bits |= extra_flags; 3232 fs_info->avail_data_alloc_bits |= extra_flags;
3232 if (flags & BTRFS_BLOCK_GROUP_METADATA) 3233 if (flags & BTRFS_BLOCK_GROUP_METADATA)
3233 fs_info->avail_metadata_alloc_bits |= extra_flags; 3234 fs_info->avail_metadata_alloc_bits |= extra_flags;
3234 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) 3235 if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
3235 fs_info->avail_system_alloc_bits |= extra_flags; 3236 fs_info->avail_system_alloc_bits |= extra_flags;
3237 write_sequnlock(&fs_info->profiles_lock);
3236} 3238}
3237 3239
3238/* 3240/*
@@ -3324,12 +3326,18 @@ u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags)
3324 3326
3325static u64 get_alloc_profile(struct btrfs_root *root, u64 flags) 3327static u64 get_alloc_profile(struct btrfs_root *root, u64 flags)
3326{ 3328{
3327 if (flags & BTRFS_BLOCK_GROUP_DATA) 3329 unsigned seq;
3328 flags |= root->fs_info->avail_data_alloc_bits; 3330
3329 else if (flags & BTRFS_BLOCK_GROUP_SYSTEM) 3331 do {
3330 flags |= root->fs_info->avail_system_alloc_bits; 3332 seq = read_seqbegin(&root->fs_info->profiles_lock);
3331 else if (flags & BTRFS_BLOCK_GROUP_METADATA) 3333
3332 flags |= root->fs_info->avail_metadata_alloc_bits; 3334 if (flags & BTRFS_BLOCK_GROUP_DATA)
3335 flags |= root->fs_info->avail_data_alloc_bits;
3336 else if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
3337 flags |= root->fs_info->avail_system_alloc_bits;
3338 else if (flags & BTRFS_BLOCK_GROUP_METADATA)
3339 flags |= root->fs_info->avail_metadata_alloc_bits;
3340 } while (read_seqretry(&root->fs_info->profiles_lock, seq));
3333 3341
3334 return btrfs_reduce_alloc_profile(root, flags); 3342 return btrfs_reduce_alloc_profile(root, flags);
3335} 3343}
@@ -7967,12 +7975,14 @@ static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
7967 u64 extra_flags = chunk_to_extended(flags) & 7975 u64 extra_flags = chunk_to_extended(flags) &
7968 BTRFS_EXTENDED_PROFILE_MASK; 7976 BTRFS_EXTENDED_PROFILE_MASK;
7969 7977
7978 write_seqlock(&fs_info->profiles_lock);
7970 if (flags & BTRFS_BLOCK_GROUP_DATA) 7979 if (flags & BTRFS_BLOCK_GROUP_DATA)
7971 fs_info->avail_data_alloc_bits &= ~extra_flags; 7980 fs_info->avail_data_alloc_bits &= ~extra_flags;
7972 if (flags & BTRFS_BLOCK_GROUP_METADATA) 7981 if (flags & BTRFS_BLOCK_GROUP_METADATA)
7973 fs_info->avail_metadata_alloc_bits &= ~extra_flags; 7982 fs_info->avail_metadata_alloc_bits &= ~extra_flags;
7974 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) 7983 if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
7975 fs_info->avail_system_alloc_bits &= ~extra_flags; 7984 fs_info->avail_system_alloc_bits &= ~extra_flags;
7985 write_sequnlock(&fs_info->profiles_lock);
7976} 7986}
7977 7987
7978int btrfs_remove_block_group(struct btrfs_trans_handle *trans, 7988int btrfs_remove_block_group(struct btrfs_trans_handle *trans,