@@ -1705,23 +1705,20 @@ static int btrfs_rm_dev_item(struct btrfs_root *root,
1705
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
1710
u64 all_avail ;
1717
- u64 devid ;
1718
1711
u64 num_devices ;
1719
- u8 * dev_uuid ;
1720
1712
unsigned seq ;
1721
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
1723
do {
1727
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
1728
root -> fs_info -> avail_metadata_alloc_bits ;
1732
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
1731
if ((all_avail & BTRFS_BLOCK_GROUP_RAID10 ) && num_devices <= 4 ) {
1743
1732
ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET ;
1744
1733
goto out ;
@@ -1760,6 +1749,30 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1760
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
1776
if (strcmp (device_path , "missing" ) == 0 ) {
1764
1777
struct list_head * devices ;
1765
1778
struct btrfs_device * tmp ;
0 commit comments