Commit 899c81ea authored by Ilya Dryomov's avatar Ilya Dryomov

Btrfs: add wrappers for working with alloc profiles

Add functions to abstract the conversion between chunk and extended
allocation profile formats and switch everybody to use them.
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent e3176ca2
...@@ -849,6 +849,21 @@ struct btrfs_csum_item { ...@@ -849,6 +849,21 @@ struct btrfs_csum_item {
*/ */
#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48) #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
BTRFS_AVAIL_ALLOC_BIT_SINGLE)
static inline u64 chunk_to_extended(u64 flags)
{
if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
return flags;
}
static inline u64 extended_to_chunk(u64 flags)
{
return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
}
struct btrfs_block_group_item { struct btrfs_block_group_item {
__le64 used; __le64 used;
__le64 chunk_objectid; __le64 chunk_objectid;
......
...@@ -3098,11 +3098,8 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags, ...@@ -3098,11 +3098,8 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
{ {
u64 extra_flags = flags & BTRFS_BLOCK_GROUP_PROFILE_MASK; u64 extra_flags = chunk_to_extended(flags) &
BTRFS_EXTENDED_PROFILE_MASK;
/* chunk -> extended profile */
if (extra_flags == 0)
extra_flags = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
if (flags & BTRFS_BLOCK_GROUP_DATA) if (flags & BTRFS_BLOCK_GROUP_DATA)
fs_info->avail_data_alloc_bits |= extra_flags; fs_info->avail_data_alloc_bits |= extra_flags;
...@@ -3181,9 +3178,7 @@ u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) ...@@ -3181,9 +3178,7 @@ u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags)
} }
out: out:
/* extended -> chunk profile */ return extended_to_chunk(flags);
flags &= ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
return flags;
} }
static u64 get_alloc_profile(struct btrfs_root *root, u64 flags) static u64 get_alloc_profile(struct btrfs_root *root, u64 flags)
...@@ -6914,11 +6909,8 @@ static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) ...@@ -6914,11 +6909,8 @@ static u64 update_block_group_flags(struct btrfs_root *root, u64 flags)
tgt = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target; tgt = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target;
} }
if (tgt) { if (tgt)
/* extended -> chunk profile */ return extended_to_chunk(tgt);
tgt &= ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
return tgt;
}
} }
/* /*
...@@ -7597,11 +7589,8 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, ...@@ -7597,11 +7589,8 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
{ {
u64 extra_flags = flags & BTRFS_BLOCK_GROUP_PROFILE_MASK; u64 extra_flags = chunk_to_extended(flags) &
BTRFS_EXTENDED_PROFILE_MASK;
/* chunk -> extended profile */
if (extra_flags == 0)
extra_flags = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
if (flags & BTRFS_BLOCK_GROUP_DATA) if (flags & BTRFS_BLOCK_GROUP_DATA)
fs_info->avail_data_alloc_bits &= ~extra_flags; fs_info->avail_data_alloc_bits &= ~extra_flags;
......
...@@ -2250,15 +2250,13 @@ static void unset_balance_control(struct btrfs_fs_info *fs_info) ...@@ -2250,15 +2250,13 @@ static void unset_balance_control(struct btrfs_fs_info *fs_info)
* Balance filters. Return 1 if chunk should be filtered out * Balance filters. Return 1 if chunk should be filtered out
* (should not be balanced). * (should not be balanced).
*/ */
static int chunk_profiles_filter(u64 chunk_profile, static int chunk_profiles_filter(u64 chunk_type,
struct btrfs_balance_args *bargs) struct btrfs_balance_args *bargs)
{ {
chunk_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK; chunk_type = chunk_to_extended(chunk_type) &
BTRFS_EXTENDED_PROFILE_MASK;
if (chunk_profile == 0) if (bargs->profiles & chunk_type)
chunk_profile = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
if (bargs->profiles & chunk_profile)
return 0; return 0;
return 1; return 1;
...@@ -2365,18 +2363,16 @@ static int chunk_vrange_filter(struct extent_buffer *leaf, ...@@ -2365,18 +2363,16 @@ static int chunk_vrange_filter(struct extent_buffer *leaf,
return 1; return 1;
} }
static int chunk_soft_convert_filter(u64 chunk_profile, static int chunk_soft_convert_filter(u64 chunk_type,
struct btrfs_balance_args *bargs) struct btrfs_balance_args *bargs)
{ {
if (!(bargs->flags & BTRFS_BALANCE_ARGS_CONVERT)) if (!(bargs->flags & BTRFS_BALANCE_ARGS_CONVERT))
return 0; return 0;
chunk_profile &= BTRFS_BLOCK_GROUP_PROFILE_MASK; chunk_type = chunk_to_extended(chunk_type) &
BTRFS_EXTENDED_PROFILE_MASK;
if (chunk_profile == 0)
chunk_profile = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
if (bargs->target & chunk_profile) if (bargs->target == chunk_type)
return 1; return 1;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment