]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: clean up and optimize __check_raid_min_device()
authorAnand Jain <anand.jain@oracle.com>
Sat, 13 Feb 2016 02:01:34 +0000 (10:01 +0800)
committerShan Hai <shan.hai@oracle.com>
Thu, 13 Jul 2017 05:20:17 +0000 (13:20 +0800)
__check_raid_min_device() which was pealed from btrfs_rm_device()
maintianed its original code to show the block move. This patch cleans up
__check_raid_min_device().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Orabug: 26287586

(Cherry picked from commit bd45ffbcb1f082e3c5a0bd56b1d7310d8b707ffb,
     drop the second argument of the btrfs_dev_replace_lock/unlock to
     match with the current kernel api)

Signed-off-by: Shan Hai <shan.hai@oracle.com>
Reviewed-by: Somasundaram Krishnasamy <somasundaram.krishnasamy@oracle.com>
fs/btrfs/volumes.c

index d609907f96143931e04060fafad5c047fbf8ebfe..399c629171244cd623b083f80f977edc0cceab97 100644 (file)
@@ -1543,52 +1543,47 @@ out:
        return ret;
 }
 
-static int __check_raid_min_devices(struct btrfs_root *root)
+static int __check_raid_min_devices(struct btrfs_fs_info *fs_info)
 {
        u64 all_avail;
        u64 num_devices;
        unsigned seq;
-       int ret = 0;
 
-       num_devices = root->fs_info->fs_devices->num_devices;
-       btrfs_dev_replace_lock(&root->fs_info->dev_replace);
-       if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) {
+       num_devices = fs_info->fs_devices->num_devices;
+       btrfs_dev_replace_lock(&fs_info->dev_replace);
+       if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) {
                WARN_ON(num_devices < 1);
                num_devices--;
        }
-       btrfs_dev_replace_unlock(&root->fs_info->dev_replace);
+       btrfs_dev_replace_unlock(&fs_info->dev_replace);
 
        do {
-               seq = read_seqbegin(&root->fs_info->profiles_lock);
+               seq = read_seqbegin(&fs_info->profiles_lock);
 
-               all_avail = root->fs_info->avail_data_alloc_bits |
-                           root->fs_info->avail_system_alloc_bits |
-                           root->fs_info->avail_metadata_alloc_bits;
-       } while (read_seqretry(&root->fs_info->profiles_lock, seq));
+               all_avail = fs_info->avail_data_alloc_bits |
+                           fs_info->avail_system_alloc_bits |
+                           fs_info->avail_metadata_alloc_bits;
+       } while (read_seqretry(&fs_info->profiles_lock, seq));
 
        if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) {
-               ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
-               goto out;
+               return BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
        }
 
        if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices <= 2) {
-               ret = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET;
-               goto out;
+               return BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET;
        }
 
        if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) &&
-           root->fs_info->fs_devices->rw_devices <= 2) {
-               ret = BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET;
-               goto out;
+           fs_info->fs_devices->rw_devices <= 2) {
+               return BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET;
        }
+
        if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) &&
-           root->fs_info->fs_devices->rw_devices <= 3) {
-               ret = BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET;
-               goto out;
+           fs_info->fs_devices->rw_devices <= 3) {
+               return BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET;
        }
 
-out:
-       return ret;
+       return 0;
 }
 
 int btrfs_rm_device(struct btrfs_root *root, char *device_path)
@@ -1607,7 +1602,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
 
        mutex_lock(&uuid_mutex);
 
-       ret = __check_raid_min_devices(root);
+       ret = __check_raid_min_devices(root->fs_info);
        if (ret)
                goto out;