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 | fc67c450837ec034174060a25889a55eed741a1d (patch) | |
tree | 0b3fb00d025427057a5171ed848c06ad0fa15222 /fs/btrfs/extent-tree.c | |
parent | 0c460c0d70e10463e44bdf1d406e9c5ec03b1af6 (diff) |
Btrfs: add get_restripe_target() helper
Add get_restripe_target() helper and switch everybody to use it.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r-- | fs/btrfs/extent-tree.c | 94 |
1 files changed, 50 insertions, 44 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 304710cae653..faf52e030315 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3110,6 +3110,35 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) | |||
3110 | } | 3110 | } |
3111 | 3111 | ||
3112 | /* | 3112 | /* |
3113 | * returns target flags in extended format or 0 if restripe for this | ||
3114 | * chunk_type is not in progress | ||
3115 | */ | ||
3116 | static u64 get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags) | ||
3117 | { | ||
3118 | struct btrfs_balance_control *bctl = fs_info->balance_ctl; | ||
3119 | u64 target = 0; | ||
3120 | |||
3121 | BUG_ON(!mutex_is_locked(&fs_info->volume_mutex) && | ||
3122 | !spin_is_locked(&fs_info->balance_lock)); | ||
3123 | |||
3124 | if (!bctl) | ||
3125 | return 0; | ||
3126 | |||
3127 | if (flags & BTRFS_BLOCK_GROUP_DATA && | ||
3128 | bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) { | ||
3129 | target = BTRFS_BLOCK_GROUP_DATA | bctl->data.target; | ||
3130 | } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM && | ||
3131 | bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) { | ||
3132 | target = BTRFS_BLOCK_GROUP_SYSTEM | bctl->sys.target; | ||
3133 | } else if (flags & BTRFS_BLOCK_GROUP_METADATA && | ||
3134 | bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) { | ||
3135 | target = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target; | ||
3136 | } | ||
3137 | |||
3138 | return target; | ||
3139 | } | ||
3140 | |||
3141 | /* | ||
3113 | * @flags: available profiles in extended format (see ctree.h) | 3142 | * @flags: available profiles in extended format (see ctree.h) |
3114 | * | 3143 | * |
3115 | * Returns reduced profile in chunk format. If profile changing is in | 3144 | * Returns reduced profile in chunk format. If profile changing is in |
@@ -3125,31 +3154,19 @@ u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) | |||
3125 | */ | 3154 | */ |
3126 | u64 num_devices = root->fs_info->fs_devices->rw_devices + | 3155 | u64 num_devices = root->fs_info->fs_devices->rw_devices + |
3127 | root->fs_info->fs_devices->missing_devices; | 3156 | root->fs_info->fs_devices->missing_devices; |
3157 | u64 target; | ||
3128 | 3158 | ||
3129 | /* pick restriper's target profile if it's available */ | 3159 | /* |
3160 | * see if restripe for this chunk_type is in progress, if so | ||
3161 | * try to reduce to the target profile | ||
3162 | */ | ||
3130 | spin_lock(&root->fs_info->balance_lock); | 3163 | spin_lock(&root->fs_info->balance_lock); |
3131 | if (root->fs_info->balance_ctl) { | 3164 | target = get_restripe_target(root->fs_info, flags); |
3132 | struct btrfs_balance_control *bctl = root->fs_info->balance_ctl; | 3165 | if (target) { |
3133 | u64 tgt = 0; | 3166 | /* pick target profile only if it's already available */ |
3134 | 3167 | if ((flags & target) & BTRFS_EXTENDED_PROFILE_MASK) { | |
3135 | if ((flags & BTRFS_BLOCK_GROUP_DATA) && | ||
3136 | (bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) && | ||
3137 | (flags & bctl->data.target)) { | ||
3138 | tgt = BTRFS_BLOCK_GROUP_DATA | bctl->data.target; | ||
3139 | } else if ((flags & BTRFS_BLOCK_GROUP_SYSTEM) && | ||
3140 | (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) && | ||
3141 | (flags & bctl->sys.target)) { | ||
3142 | tgt = BTRFS_BLOCK_GROUP_SYSTEM | bctl->sys.target; | ||
3143 | } else if ((flags & BTRFS_BLOCK_GROUP_METADATA) && | ||
3144 | (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) && | ||
3145 | (flags & bctl->meta.target)) { | ||
3146 | tgt = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target; | ||
3147 | } | ||
3148 | |||
3149 | if (tgt) { | ||
3150 | spin_unlock(&root->fs_info->balance_lock); | 3168 | spin_unlock(&root->fs_info->balance_lock); |
3151 | flags = tgt; | 3169 | return extended_to_chunk(target); |
3152 | goto out; | ||
3153 | } | 3170 | } |
3154 | } | 3171 | } |
3155 | spin_unlock(&root->fs_info->balance_lock); | 3172 | spin_unlock(&root->fs_info->balance_lock); |
@@ -3177,7 +3194,6 @@ u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) | |||
3177 | flags &= ~BTRFS_BLOCK_GROUP_RAID0; | 3194 | flags &= ~BTRFS_BLOCK_GROUP_RAID0; |
3178 | } | 3195 | } |
3179 | 3196 | ||
3180 | out: | ||
3181 | return extended_to_chunk(flags); | 3197 | return extended_to_chunk(flags); |
3182 | } | 3198 | } |
3183 | 3199 | ||
@@ -6888,28 +6904,15 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, | |||
6888 | static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) | 6904 | static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) |
6889 | { | 6905 | { |
6890 | u64 num_devices; | 6906 | u64 num_devices; |
6891 | u64 stripped = BTRFS_BLOCK_GROUP_RAID0 | | 6907 | u64 stripped; |
6892 | BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10; | ||
6893 | |||
6894 | if (root->fs_info->balance_ctl) { | ||
6895 | struct btrfs_balance_control *bctl = root->fs_info->balance_ctl; | ||
6896 | u64 tgt = 0; | ||
6897 | |||
6898 | /* pick restriper's target profile and return */ | ||
6899 | if (flags & BTRFS_BLOCK_GROUP_DATA && | ||
6900 | bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) { | ||
6901 | tgt = BTRFS_BLOCK_GROUP_DATA | bctl->data.target; | ||
6902 | } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM && | ||
6903 | bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) { | ||
6904 | tgt = BTRFS_BLOCK_GROUP_SYSTEM | bctl->sys.target; | ||
6905 | } else if (flags & BTRFS_BLOCK_GROUP_METADATA && | ||
6906 | bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) { | ||
6907 | tgt = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target; | ||
6908 | } | ||
6909 | 6908 | ||
6910 | if (tgt) | 6909 | /* |
6911 | return extended_to_chunk(tgt); | 6910 | * if restripe for this chunk_type is on pick target profile and |
6912 | } | 6911 | * return, otherwise do the usual balance |
6912 | */ | ||
6913 | stripped = get_restripe_target(root->fs_info, flags); | ||
6914 | if (stripped) | ||
6915 | return extended_to_chunk(stripped); | ||
6913 | 6916 | ||
6914 | /* | 6917 | /* |
6915 | * we add in the count of missing devices because we want | 6918 | * we add in the count of missing devices because we want |
@@ -6919,6 +6922,9 @@ static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) | |||
6919 | num_devices = root->fs_info->fs_devices->rw_devices + | 6922 | num_devices = root->fs_info->fs_devices->rw_devices + |
6920 | root->fs_info->fs_devices->missing_devices; | 6923 | root->fs_info->fs_devices->missing_devices; |
6921 | 6924 | ||
6925 | stripped = BTRFS_BLOCK_GROUP_RAID0 | | ||
6926 | BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10; | ||
6927 | |||
6922 | if (num_devices == 1) { | 6928 | if (num_devices == 1) { |
6923 | stripped |= BTRFS_BLOCK_GROUP_DUP; | 6929 | stripped |= BTRFS_BLOCK_GROUP_DUP; |
6924 | stripped = flags & ~stripped; | 6930 | stripped = flags & ~stripped; |