diff options
author | Anand Jain <anand.jain@oracle.com> | 2016-02-12 21:01:34 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-04-28 04:59:13 -0400 |
commit | bd45ffbcb1f082e3c5a0bd56b1d7310d8b707ffb (patch) | |
tree | 02925be50b0ecff12c57694e127df483a4246b7d | |
parent | f1fa7f264250f2cb60119aca3fd114c3f47070c2 (diff) |
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 <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/volumes.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index db781d0d3678..5538dc78c72e 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -1705,52 +1705,47 @@ out: | |||
1705 | return ret; | 1705 | return ret; |
1706 | } | 1706 | } |
1707 | 1707 | ||
1708 | static int __check_raid_min_devices(struct btrfs_root *root) | 1708 | static int __check_raid_min_devices(struct btrfs_fs_info *fs_info) |
1709 | { | 1709 | { |
1710 | u64 all_avail; | 1710 | u64 all_avail; |
1711 | u64 num_devices; | 1711 | u64 num_devices; |
1712 | unsigned seq; | 1712 | unsigned seq; |
1713 | int ret = 0; | ||
1714 | 1713 | ||
1715 | num_devices = root->fs_info->fs_devices->num_devices; | 1714 | num_devices = fs_info->fs_devices->num_devices; |
1716 | btrfs_dev_replace_lock(&root->fs_info->dev_replace, 0); | 1715 | btrfs_dev_replace_lock(&fs_info->dev_replace, 0); |
1717 | if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) { | 1716 | if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) { |
1718 | WARN_ON(num_devices < 1); | 1717 | WARN_ON(num_devices < 1); |
1719 | num_devices--; | 1718 | num_devices--; |
1720 | } | 1719 | } |
1721 | btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0); | 1720 | btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); |
1722 | 1721 | ||
1723 | do { | 1722 | do { |
1724 | seq = read_seqbegin(&root->fs_info->profiles_lock); | 1723 | seq = read_seqbegin(&fs_info->profiles_lock); |
1725 | 1724 | ||
1726 | all_avail = root->fs_info->avail_data_alloc_bits | | 1725 | all_avail = fs_info->avail_data_alloc_bits | |
1727 | root->fs_info->avail_system_alloc_bits | | 1726 | fs_info->avail_system_alloc_bits | |
1728 | root->fs_info->avail_metadata_alloc_bits; | 1727 | fs_info->avail_metadata_alloc_bits; |
1729 | } while (read_seqretry(&root->fs_info->profiles_lock, seq)); | 1728 | } while (read_seqretry(&fs_info->profiles_lock, seq)); |
1730 | 1729 | ||
1731 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) { | 1730 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) { |
1732 | ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET; | 1731 | return BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET; |
1733 | goto out; | ||
1734 | } | 1732 | } |
1735 | 1733 | ||
1736 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices <= 2) { | 1734 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices <= 2) { |
1737 | ret = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET; | 1735 | return BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET; |
1738 | goto out; | ||
1739 | } | 1736 | } |
1740 | 1737 | ||
1741 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) && | 1738 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) && |
1742 | root->fs_info->fs_devices->rw_devices <= 2) { | 1739 | fs_info->fs_devices->rw_devices <= 2) { |
1743 | ret = BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET; | 1740 | return BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET; |
1744 | goto out; | ||
1745 | } | 1741 | } |
1742 | |||
1746 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) && | 1743 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) && |
1747 | root->fs_info->fs_devices->rw_devices <= 3) { | 1744 | fs_info->fs_devices->rw_devices <= 3) { |
1748 | ret = BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET; | 1745 | return BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET; |
1749 | goto out; | ||
1750 | } | 1746 | } |
1751 | 1747 | ||
1752 | out: | 1748 | return 0; |
1753 | return ret; | ||
1754 | } | 1749 | } |
1755 | 1750 | ||
1756 | int btrfs_rm_device(struct btrfs_root *root, char *device_path) | 1751 | 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) | |||
1769 | 1764 | ||
1770 | mutex_lock(&uuid_mutex); | 1765 | mutex_lock(&uuid_mutex); |
1771 | 1766 | ||
1772 | ret = __check_raid_min_devices(root); | 1767 | ret = __check_raid_min_devices(root->fs_info); |
1773 | if (ret) | 1768 | if (ret) |
1774 | goto out; | 1769 | goto out; |
1775 | 1770 | ||