diff options
| -rw-r--r-- | fs/btrfs/volumes.c | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9956c53f18f6..a735576471a9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
| @@ -3700,17 +3700,11 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) | |||
| 3700 | { | 3700 | { |
| 3701 | struct btrfs_balance_control *bctl = fs_info->balance_ctl; | 3701 | struct btrfs_balance_control *bctl = fs_info->balance_ctl; |
| 3702 | struct btrfs_root *chunk_root = fs_info->chunk_root; | 3702 | struct btrfs_root *chunk_root = fs_info->chunk_root; |
| 3703 | struct btrfs_root *dev_root = fs_info->dev_root; | ||
| 3704 | struct list_head *devices; | ||
| 3705 | struct btrfs_device *device; | ||
| 3706 | u64 old_size; | ||
| 3707 | u64 size_to_free; | ||
| 3708 | u64 chunk_type; | 3703 | u64 chunk_type; |
| 3709 | struct btrfs_chunk *chunk; | 3704 | struct btrfs_chunk *chunk; |
| 3710 | struct btrfs_path *path = NULL; | 3705 | struct btrfs_path *path = NULL; |
| 3711 | struct btrfs_key key; | 3706 | struct btrfs_key key; |
| 3712 | struct btrfs_key found_key; | 3707 | struct btrfs_key found_key; |
| 3713 | struct btrfs_trans_handle *trans; | ||
| 3714 | struct extent_buffer *leaf; | 3708 | struct extent_buffer *leaf; |
| 3715 | int slot; | 3709 | int slot; |
| 3716 | int ret; | 3710 | int ret; |
| @@ -3725,53 +3719,6 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) | |||
| 3725 | u32 count_sys = 0; | 3719 | u32 count_sys = 0; |
| 3726 | int chunk_reserved = 0; | 3720 | int chunk_reserved = 0; |
| 3727 | 3721 | ||
| 3728 | /* step one make some room on all the devices */ | ||
| 3729 | devices = &fs_info->fs_devices->devices; | ||
| 3730 | list_for_each_entry(device, devices, dev_list) { | ||
| 3731 | old_size = btrfs_device_get_total_bytes(device); | ||
| 3732 | size_to_free = div_factor(old_size, 1); | ||
| 3733 | size_to_free = min_t(u64, size_to_free, SZ_1M); | ||
| 3734 | if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) || | ||
| 3735 | btrfs_device_get_total_bytes(device) - | ||
| 3736 | btrfs_device_get_bytes_used(device) > size_to_free || | ||
| 3737 | test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) | ||
| 3738 | continue; | ||
| 3739 | |||
| 3740 | ret = btrfs_shrink_device(device, old_size - size_to_free); | ||
| 3741 | if (ret == -ENOSPC) | ||
| 3742 | break; | ||
| 3743 | if (ret) { | ||
| 3744 | /* btrfs_shrink_device never returns ret > 0 */ | ||
| 3745 | WARN_ON(ret > 0); | ||
| 3746 | goto error; | ||
| 3747 | } | ||
| 3748 | |||
| 3749 | trans = btrfs_start_transaction(dev_root, 0); | ||
| 3750 | if (IS_ERR(trans)) { | ||
| 3751 | ret = PTR_ERR(trans); | ||
| 3752 | btrfs_info_in_rcu(fs_info, | ||
| 3753 | "resize: unable to start transaction after shrinking device %s (error %d), old size %llu, new size %llu", | ||
| 3754 | rcu_str_deref(device->name), ret, | ||
| 3755 | old_size, old_size - size_to_free); | ||
| 3756 | goto error; | ||
| 3757 | } | ||
| 3758 | |||
| 3759 | ret = btrfs_grow_device(trans, device, old_size); | ||
| 3760 | if (ret) { | ||
| 3761 | btrfs_end_transaction(trans); | ||
| 3762 | /* btrfs_grow_device never returns ret > 0 */ | ||
| 3763 | WARN_ON(ret > 0); | ||
| 3764 | btrfs_info_in_rcu(fs_info, | ||
| 3765 | "resize: unable to grow device after shrinking device %s (error %d), old size %llu, new size %llu", | ||
| 3766 | rcu_str_deref(device->name), ret, | ||
| 3767 | old_size, old_size - size_to_free); | ||
| 3768 | goto error; | ||
| 3769 | } | ||
| 3770 | |||
| 3771 | btrfs_end_transaction(trans); | ||
| 3772 | } | ||
| 3773 | |||
| 3774 | /* step two, relocate all the chunks */ | ||
| 3775 | path = btrfs_alloc_path(); | 3722 | path = btrfs_alloc_path(); |
| 3776 | if (!path) { | 3723 | if (!path) { |
| 3777 | ret = -ENOMEM; | 3724 | ret = -ENOMEM; |
