aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/volumes.c
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2012-03-27 10:09:17 -0400
committerIlya Dryomov <idryomov@gmail.com>2012-03-27 10:09:17 -0400
commit6728b198deb02c187b5e5a99eb7d1cc9c8bc65e9 (patch)
treecaf0f07250c8df5cb97551088395748eb9e753ff /fs/btrfs/volumes.c
parent4a5e98f5d61f698452e564e0cde34c16a6b65752 (diff)
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>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r--fs/btrfs/volumes.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index def9e25f87f2..28addea5b0f2 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2676,14 +2676,6 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
2676 } 2676 }
2677 } 2677 }
2678 2678
2679 /*
2680 * Profile changing sanity checks. Skip them if a simple
2681 * balance is requested.
2682 */
2683 if (!((bctl->data.flags | bctl->sys.flags | bctl->meta.flags) &
2684 BTRFS_BALANCE_ARGS_CONVERT))
2685 goto do_balance;
2686
2687 allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE; 2679 allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE;
2688 if (fs_info->fs_devices->num_devices == 1) 2680 if (fs_info->fs_devices->num_devices == 1)
2689 allowed |= BTRFS_BLOCK_GROUP_DUP; 2681 allowed |= BTRFS_BLOCK_GROUP_DUP;
@@ -2693,24 +2685,27 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
2693 allowed |= (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 | 2685 allowed |= (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 |
2694 BTRFS_BLOCK_GROUP_RAID10); 2686 BTRFS_BLOCK_GROUP_RAID10);
2695 2687
2696 if (!alloc_profile_is_valid(bctl->data.target, 1) || 2688 if ((bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
2697 bctl->data.target & ~allowed) { 2689 (!alloc_profile_is_valid(bctl->data.target, 1) ||
2690 (bctl->data.target & ~allowed))) {
2698 printk(KERN_ERR "btrfs: unable to start balance with target " 2691 printk(KERN_ERR "btrfs: unable to start balance with target "
2699 "data profile %llu\n", 2692 "data profile %llu\n",
2700 (unsigned long long)bctl->data.target); 2693 (unsigned long long)bctl->data.target);
2701 ret = -EINVAL; 2694 ret = -EINVAL;
2702 goto out; 2695 goto out;
2703 } 2696 }
2704 if (!alloc_profile_is_valid(bctl->meta.target, 1) || 2697 if ((bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
2705 bctl->meta.target & ~allowed) { 2698 (!alloc_profile_is_valid(bctl->meta.target, 1) ||
2699 (bctl->meta.target & ~allowed))) {
2706 printk(KERN_ERR "btrfs: unable to start balance with target " 2700 printk(KERN_ERR "btrfs: unable to start balance with target "
2707 "metadata profile %llu\n", 2701 "metadata profile %llu\n",
2708 (unsigned long long)bctl->meta.target); 2702 (unsigned long long)bctl->meta.target);
2709 ret = -EINVAL; 2703 ret = -EINVAL;
2710 goto out; 2704 goto out;
2711 } 2705 }
2712 if (!alloc_profile_is_valid(bctl->sys.target, 1) || 2706 if ((bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
2713 bctl->sys.target & ~allowed) { 2707 (!alloc_profile_is_valid(bctl->sys.target, 1) ||
2708 (bctl->sys.target & ~allowed))) {
2714 printk(KERN_ERR "btrfs: unable to start balance with target " 2709 printk(KERN_ERR "btrfs: unable to start balance with target "
2715 "system profile %llu\n", 2710 "system profile %llu\n",
2716 (unsigned long long)bctl->sys.target); 2711 (unsigned long long)bctl->sys.target);
@@ -2718,7 +2713,8 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
2718 goto out; 2713 goto out;
2719 } 2714 }
2720 2715
2721 if (bctl->data.target & BTRFS_BLOCK_GROUP_DUP) { 2716 if ((bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) &&
2717 (bctl->data.target & BTRFS_BLOCK_GROUP_DUP)) {
2722 printk(KERN_ERR "btrfs: dup for data is not allowed\n"); 2718 printk(KERN_ERR "btrfs: dup for data is not allowed\n");
2723 ret = -EINVAL; 2719 ret = -EINVAL;
2724 goto out; 2720 goto out;
@@ -2744,7 +2740,6 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
2744 } 2740 }
2745 } 2741 }
2746 2742
2747do_balance:
2748 ret = insert_balance_item(fs_info->tree_root, bctl); 2743 ret = insert_balance_item(fs_info->tree_root, bctl);
2749 if (ret && ret != -EEXIST) 2744 if (ret && ret != -EEXIST)
2750 goto out; 2745 goto out;