diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2012-03-27 10:09:17 -0400 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2012-03-27 10:09:17 -0400 |
commit | e8920a640be5d4ebe3fee0670639a81d4ffc904c (patch) | |
tree | 0c999adbdce223ac0365ca98c008da8db7bb7cb3 /fs/btrfs/ctree.h | |
parent | 899c81eac890bcfa5f3636f4c43f68e8393ac1f8 (diff) |
Btrfs: make profile_is_valid() check more strict
"0" is a valid value for an on-disk chunk profile, but it is not a valid
extended profile. (We have a separate bit for single chunks in extended
case)
Also rename it to alloc_profile_is_valid() for clarity.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index aba7832a2285..f057e92df39f 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -2735,22 +2735,27 @@ static inline void free_fs_info(struct btrfs_fs_info *fs_info) | |||
2735 | kfree(fs_info); | 2735 | kfree(fs_info); |
2736 | } | 2736 | } |
2737 | /** | 2737 | /** |
2738 | * profile_is_valid - tests whether a given profile is valid and reduced | 2738 | * alloc_profile_is_valid - see if a given profile is valid and reduced |
2739 | * @flags: profile to validate | 2739 | * @flags: profile to validate |
2740 | * @extended: if true @flags is treated as an extended profile | 2740 | * @extended: if true @flags is treated as an extended profile |
2741 | */ | 2741 | */ |
2742 | static inline int profile_is_valid(u64 flags, int extended) | 2742 | static inline int alloc_profile_is_valid(u64 flags, int extended) |
2743 | { | 2743 | { |
2744 | u64 mask = ~BTRFS_BLOCK_GROUP_PROFILE_MASK; | 2744 | u64 mask = (extended ? BTRFS_EXTENDED_PROFILE_MASK : |
2745 | BTRFS_BLOCK_GROUP_PROFILE_MASK); | ||
2745 | 2746 | ||
2746 | flags &= ~BTRFS_BLOCK_GROUP_TYPE_MASK; | 2747 | flags &= ~BTRFS_BLOCK_GROUP_TYPE_MASK; |
2747 | if (extended) | ||
2748 | mask &= ~BTRFS_AVAIL_ALLOC_BIT_SINGLE; | ||
2749 | 2748 | ||
2750 | if (flags & mask) | 2749 | /* 1) check that all other bits are zeroed */ |
2750 | if (flags & ~mask) | ||
2751 | return 0; | 2751 | return 0; |
2752 | /* true if zero or exactly one bit set */ | 2752 | |
2753 | return (flags & (~flags + 1)) == flags; | 2753 | /* 2) see if profile is reduced */ |
2754 | if (flags == 0) | ||
2755 | return !extended; /* "0" is valid for usual profiles */ | ||
2756 | |||
2757 | /* true if exactly one bit set */ | ||
2758 | return (flags & (flags - 1)) == 0; | ||
2754 | } | 2759 | } |
2755 | 2760 | ||
2756 | /* root-item.c */ | 2761 | /* root-item.c */ |