Btrfs: validate target profiles only if we are going to use them

Do not run sanity checks on all target profiles unless they all will be
used.  This came up because alloc_profile_is_valid() is now more strict
than it used to be.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
Ilya Dryomov 2012-03-27 17:09:17 +03:00
parent 4a5e98f5d6
commit 6728b198de

View file

@ -2676,14 +2676,6 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
} }
} }
/*
* Profile changing sanity checks. Skip them if a simple
* balance is requested.
*/
if (!((bctl->data.flags | bctl->sys.flags | bctl->meta.flags) &
BTRFS_BALANCE_ARGS_CONVERT))
goto do_balance;
allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE; allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
if (fs_info->fs_devices->num_devices == 1) if (fs_info->fs_devices->num_devices == 1)
allowed |= BTRFS_BLOCK_GROUP_DUP; allowed |= BTRFS_BLOCK_GROUP_DUP;
@ -2693,24 +2685,27 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
allowed |= (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 | allowed |= (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
BTRFS_BLOCK_GROUP_RAID10); BTRFS_BLOCK_GROUP_RAID10);
if (!alloc_profile_is_valid(bctl->data.target, 1) || if ((bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
bctl->data.target & ~allowed) { (!alloc_profile_is_valid(bctl->data.target, 1) ||
(bctl->data.target & ~allowed))) {
printk(KERN_ERR "btrfs: unable to start balance with target " printk(KERN_ERR "btrfs: unable to start balance with target "
"data profile %llu\n", "data profile %llu\n",
(unsigned long long)bctl->data.target); (unsigned long long)bctl->data.target);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
if (!alloc_profile_is_valid(bctl->meta.target, 1) || if ((bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
bctl->meta.target & ~allowed) { (!alloc_profile_is_valid(bctl->meta.target, 1) ||
(bctl->meta.target & ~allowed))) {
printk(KERN_ERR "btrfs: unable to start balance with target " printk(KERN_ERR "btrfs: unable to start balance with target "
"metadata profile %llu\n", "metadata profile %llu\n",
(unsigned long long)bctl->meta.target); (unsigned long long)bctl->meta.target);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
if (!alloc_profile_is_valid(bctl->sys.target, 1) || if ((bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
bctl->sys.target & ~allowed) { (!alloc_profile_is_valid(bctl->sys.target, 1) ||
(bctl->sys.target & ~allowed))) {
printk(KERN_ERR "btrfs: unable to start balance with target " printk(KERN_ERR "btrfs: unable to start balance with target "
"system profile %llu\n", "system profile %llu\n",
(unsigned long long)bctl->sys.target); (unsigned long long)bctl->sys.target);
@ -2718,7 +2713,8 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
goto out; goto out;
} }
if (bctl->data.target & BTRFS_BLOCK_GROUP_DUP) { if ((bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
(bctl->data.target & BTRFS_BLOCK_GROUP_DUP)) {
printk(KERN_ERR "btrfs: dup for data is not allowed\n"); printk(KERN_ERR "btrfs: dup for data is not allowed\n");
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
@ -2744,7 +2740,6 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
} }
} }
do_balance:
ret = insert_balance_item(fs_info->tree_root, bctl); ret = insert_balance_item(fs_info->tree_root, bctl);
if (ret && ret != -EEXIST) if (ret && ret != -EEXIST)
goto out; goto out;