Skip to content

Commit f1fa7f2

Browse files
asjkdave
authored andcommitted
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 <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 6cf86a0 commit f1fa7f2

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

fs/btrfs/volumes.c

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

1708-
int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1708+
static int __check_raid_min_devices(struct btrfs_root *root)
17091709
{
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;
17161710
u64 all_avail;
1717-
u64 devid;
17181711
u64 num_devices;
1719-
u8 *dev_uuid;
17201712
unsigned seq;
17211713
int ret = 0;
1722-
bool clear_super = false;
17231714

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);
17251722

17261723
do {
17271724
seq = read_seqbegin(&root->fs_info->profiles_lock);
@@ -1731,14 +1728,6 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
17311728
root->fs_info->avail_metadata_alloc_bits;
17321729
} while (read_seqretry(&root->fs_info->profiles_lock, seq));
17331730

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-
17421731
if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) {
17431732
ret = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
17441733
goto out;
@@ -1760,6 +1749,30 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
17601749
goto out;
17611750
}
17621751

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+
17631776
if (strcmp(device_path, "missing") == 0) {
17641777
struct list_head *devices;
17651778
struct btrfs_device *tmp;

0 commit comments

Comments
 (0)