summaryrefslogtreecommitdiff
path: root/fs/btrfs/volumes.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-02-15 16:00:26 +0100
committerDavid Sterba <dsterba@suse.com>2016-04-28 10:59:13 +0200
commit3cc31a0d5bc77e35229671307eba5ea5c4c4cb9d (patch)
tree8d2351bcfb4f81b9e70112b6d8e4b0bfd997ecb5 /fs/btrfs/volumes.c
parentf47ab2588e424cb4898b75ace1e2323ddd18b990 (diff)
btrfs: pass number of devices to btrfs_check_raid_min_devices
Before this patch, btrfs_check_raid_min_devices would do an off-by-one check of the constraints and not the miminmum check, as its name suggests. This is not a problem if the only caller is device remove, but would be confusing for others. Add an argument with the exact number and let the caller(s) decide if this needs any adjustments, like when device replace is running. Reviewed-by: Anand Jain <anand.jain@oracle.com> Tested-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r--fs/btrfs/volumes.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9051b4472bea..e966f0ce07f8 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1706,20 +1706,17 @@ out:
return ret;
}
-static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info)
+/*
+ * Verify that @num_devices satisfies the RAID profile constraints in the whole
+ * filesystem. It's up to the caller to adjust that number regarding eg. device
+ * replace.
+ */
+static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info,
+ u64 num_devices)
{
u64 all_avail;
- u64 num_devices;
unsigned seq;
- num_devices = fs_info->fs_devices->num_devices;
- btrfs_dev_replace_lock(&fs_info->dev_replace, 0);
- if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) {
- WARN_ON(num_devices < 1);
- num_devices--;
- }
- btrfs_dev_replace_unlock(&fs_info->dev_replace, 0);
-
do {
seq = read_seqbegin(&fs_info->profiles_lock);
@@ -1728,21 +1725,21 @@ static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info)
fs_info->avail_metadata_alloc_bits;
} while (read_seqretry(&fs_info->profiles_lock, seq));
- if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices <= 4) {
+ if ((all_avail & BTRFS_BLOCK_GROUP_RAID10) && num_devices < 4) {
return BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET;
}
- if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices <= 2) {
+ if ((all_avail & BTRFS_BLOCK_GROUP_RAID1) && num_devices < 2) {
return BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET;
}
if ((all_avail & BTRFS_BLOCK_GROUP_RAID5) &&
- fs_info->fs_devices->rw_devices <= 2) {
+ fs_info->fs_devices->rw_devices < 2) {
return BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET;
}
if ((all_avail & BTRFS_BLOCK_GROUP_RAID6) &&
- fs_info->fs_devices->rw_devices <= 3) {
+ fs_info->fs_devices->rw_devices < 3) {
return BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET;
}
@@ -1761,7 +1758,15 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path, u64 devid)
mutex_lock(&uuid_mutex);
- ret = btrfs_check_raid_min_devices(root->fs_info);
+ num_devices = root->fs_info->fs_devices->num_devices;
+ btrfs_dev_replace_lock(&root->fs_info->dev_replace, 0);
+ if (btrfs_dev_replace_is_ongoing(&root->fs_info->dev_replace)) {
+ WARN_ON(num_devices < 1);
+ num_devices--;
+ }
+ btrfs_dev_replace_unlock(&root->fs_info->dev_replace, 0);
+
+ ret = btrfs_check_raid_min_devices(root->fs_info, num_devices - 1);
if (ret)
goto out;