diff options
author | Anand Jain <anand.jain@oracle.com> | 2016-02-12 21:01:33 -0500 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-04-28 04:59:13 -0400 |
commit | f1fa7f264250f2cb60119aca3fd114c3f47070c2 (patch) | |
tree | 6e153fa78b7d53b7425dd15152663dd8e5d1fb73 | |
parent | 6cf86a006be9f2a77434d5a06ea289719815ad7c (diff) |
btrfs: create helper function __check_raid_min_devices()
move a section of btrfs_rm_device() code to check for min number of the
devices into the function __check_raid_min_devices()
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/volumes.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5006683283ae..db781d0d3678 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -1705,23 +1705,20 @@ out: | |||
1705 | return ret; | 1705 | return ret; |
1706 | } | 1706 | } |
1707 | 1707 | ||
1708 | int btrfs_rm_device(struct btrfs_root *root, char *device_path) | 1708 | static int __check_raid_min_devices(struct btrfs_root *root) |
1709 | { | 1709 | { |
1710 | struct btrfs_device *device; | ||
1711 | struct btrfs_device *next_device; | ||
1712 | struct block_device *bdev; | ||
1713 | struct buffer_head *bh = NULL; | ||
1714 | struct btrfs_super_block *disk_super; | ||
1715 | struct btrfs_fs_devices *cur_devices; | ||
1716 | u64 all_avail; | 1710 | u64 all_avail; |
1717 | u64 devid; | ||
1718 | u64 num_devices; | 1711 | u64 num_devices; |
1719 | u8 *dev_uuid; | ||
1720 | unsigned seq; | 1712 | unsigned seq; |
1721 | int ret = 0; | 1713 | int ret = 0; |
1722 | bool clear_super = false; | ||
1723 | 1714 | ||
1724 | mutex_lock(&uuid_mutex); | 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)) { | ||
1718 | WARN_ON(num_devices < 1); | ||
1719 | num_devices--; | ||
1720 | } | ||
1721 | btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0); | ||
1725 | 1722 | ||
1726 | do { | 1723 | do { |
1727 | seq = read_seqbegin(&root->fs_info->profiles_lock); | 1724 | seq = read_seqbegin(&root->fs_info->profiles_lock); |
@@ -1731,14 +1728,6 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) | |||
1731 | root->fs_info->avail_metadata_alloc_bits; | 1728 | root->fs_info->avail_metadata_alloc_bits; |
1732 | } while (read_seqretry(&root->fs_info->profiles_lock, seq)); | 1729 | } while (read_seqretry(&root->fs_info->profiles_lock, seq)); |
1733 | 1730 | ||
1734 | num_devices = root->fs_info->fs_devices->num_devices; | ||
1735 | btrfs_dev_replace_lock(&root->fs_info->dev_replace, 0); | ||
1736 | if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) { | ||
1737 | WARN_ON(num_devices < 1); | ||
1738 | num_devices--; | ||
1739 | } | ||
1740 | btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0); | ||
1741 | |||
1742 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) { | 1731 | if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) { |
1743 | ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET; | 1732 | ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET; |
1744 | goto out; | 1733 | goto out; |
@@ -1760,6 +1749,30 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) | |||
1760 | goto out; | 1749 | goto out; |
1761 | } | 1750 | } |
1762 | 1751 | ||
1752 | out: | ||
1753 | return ret; | ||
1754 | } | ||
1755 | |||
1756 | int btrfs_rm_device(struct btrfs_root *root, char *device_path) | ||
1757 | { | ||
1758 | struct btrfs_device *device; | ||
1759 | struct btrfs_device *next_device; | ||
1760 | struct block_device *bdev; | ||
1761 | struct buffer_head *bh = NULL; | ||
1762 | struct btrfs_super_block *disk_super; | ||
1763 | struct btrfs_fs_devices *cur_devices; | ||
1764 | u64 devid; | ||
1765 | u64 num_devices; | ||
1766 | u8 *dev_uuid; | ||
1767 | int ret = 0; | ||
1768 | bool clear_super = false; | ||
1769 | |||
1770 | mutex_lock(&uuid_mutex); | ||
1771 | |||
1772 | ret = __check_raid_min_devices(root); | ||
1773 | if (ret) | ||
1774 | goto out; | ||
1775 | |||
1763 | if (strcmp(device_path, "missing") == 0) { | 1776 | if (strcmp(device_path, "missing") == 0) { |
1764 | struct list_head *devices; | 1777 | struct list_head *devices; |
1765 | struct btrfs_device *tmp; | 1778 | struct btrfs_device *tmp; |