Skip to content

Commit bd45ffb

Browse files
asjkdave
authored andcommitted
btrfs: clean up and optimize __check_raid_min_device()
__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 <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f1fa7f2 commit bd45ffb

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

fs/btrfs/volumes.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,52 +1705,47 @@ static int btrfs_rm_dev_item(struct btrfs_root *root,
17051705
return ret;
17061706
}
17071707

1708-
static int __check_raid_min_devices(struct btrfs_root *root)
1708+
static int __check_raid_min_devices(struct btrfs_fs_info *fs_info)
17091709
{
17101710
u64 all_avail;
17111711
u64 num_devices;
17121712
unsigned seq;
1713-
int ret = 0;
17141713

1715-
num_devices = root->fs_info->fs_devices->num_devices;
1716-
btrfs_dev_replace_lock(&root->fs_info->dev_replace, 0);
1717-
if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) {
1714+
num_devices = fs_info->fs_devices->num_devices;
1715+
btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
1716+
if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) {
17181717
WARN_ON(num_devices < 1);
17191718
num_devices--;
17201719
}
1721-
btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0);
1720+
btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
17221721

17231722
do {
1724-
seq = read_seqbegin(&root->fs_info->profiles_lock);
1723+
seq = read_seqbegin(&fs_info->profiles_lock);
17251724

1726-
all_avail = root->fs_info->avail_data_alloc_bits |
1727-
root->fs_info->avail_system_alloc_bits |
1728-
root->fs_info->avail_metadata_alloc_bits;
1729-
} while (read_seqretry(&root->fs_info->profiles_lock, seq));
1725+
all_avail = fs_info->avail_data_alloc_bits |
1726+
fs_info->avail_system_alloc_bits |
1727+
fs_info->avail_metadata_alloc_bits;
1728+
} while (read_seqretry(&fs_info->profiles_lock, seq));
17301729

17311730
if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) {
1732-
ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
1733-
goto out;
1731+
return BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
17341732
}
17351733

17361734
if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices <= 2) {
1737-
ret = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET;
1738-
goto out;
1735+
return BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET;
17391736
}
17401737

17411738
if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) &&
1742-
root->fs_info->fs_devices->rw_devices <= 2) {
1743-
ret = BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET;
1744-
goto out;
1739+
fs_info->fs_devices->rw_devices <= 2) {
1740+
return BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET;
17451741
}
1742+
17461743
if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) &&
1747-
root->fs_info->fs_devices->rw_devices <= 3) {
1748-
ret = BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET;
1749-
goto out;
1744+
fs_info->fs_devices->rw_devices <= 3) {
1745+
return BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET;
17501746
}
17511747

1752-
out:
1753-
return ret;
1748+
return 0;
17541749
}
17551750

17561751
int btrfs_rm_device(struct btrfs_root *root, char *device_path)
@@ -1769,7 +1764,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
17691764

17701765
mutex_lock(&uuid_mutex);
17711766

1772-
ret = __check_raid_min_devices(root);
1767+
ret = __check_raid_min_devices(root->fs_info);
17731768
if (ret)
17741769
goto out;
17751770

0 commit comments

Comments
 (0)