Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c170b26 authored by Zhao Lei's avatar Zhao Lei Committed by David Sterba
Browse files

btrfs: use btrfs_raid_array in btrfs_reduce_alloc_profile



btrfs_raid_array[] holds attributes of all raid types.

Use btrfs_raid_array[].devs_min is best way for request
in btrfs_reduce_alloc_profile(), instead of use complex
condition of each raid types.

Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarZhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 8789f4fe
Loading
Loading
Loading
Loading
+22 −26
Original line number Original line Diff line number Diff line
@@ -3822,7 +3822,8 @@ static u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags)
{
{
	u64 num_devices = root->fs_info->fs_devices->rw_devices;
	u64 num_devices = root->fs_info->fs_devices->rw_devices;
	u64 target;
	u64 target;
	u64 tmp;
	u64 raid_type;
	u64 allowed = 0;


	/*
	/*
	 * see if restripe for this chunk_type is in progress, if so
	 * see if restripe for this chunk_type is in progress, if so
@@ -3840,31 +3841,26 @@ static u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags)
	spin_unlock(&root->fs_info->balance_lock);
	spin_unlock(&root->fs_info->balance_lock);


	/* First, mask out the RAID levels which aren't possible */
	/* First, mask out the RAID levels which aren't possible */
	if (num_devices == 1)
	for (raid_type = 0; raid_type < BTRFS_NR_RAID_TYPES; raid_type++) {
		flags &= ~(BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID0 |
		if (num_devices >= btrfs_raid_array[raid_type].devs_min)
			   BTRFS_BLOCK_GROUP_RAID5);
			allowed |= btrfs_raid_group[raid_type];
	if (num_devices < 3)
	}
		flags &= ~BTRFS_BLOCK_GROUP_RAID6;
	allowed &= flags;
	if (num_devices < 4)

		flags &= ~BTRFS_BLOCK_GROUP_RAID10;
	if (allowed & BTRFS_BLOCK_GROUP_RAID6)

		allowed = BTRFS_BLOCK_GROUP_RAID6;
	tmp = flags & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID0 |
	else if (allowed & BTRFS_BLOCK_GROUP_RAID5)
		       BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID5 |
		allowed = BTRFS_BLOCK_GROUP_RAID5;
		       BTRFS_BLOCK_GROUP_RAID6 | BTRFS_BLOCK_GROUP_RAID10);
	else if (allowed & BTRFS_BLOCK_GROUP_RAID10)
	flags &= ~tmp;
		allowed = BTRFS_BLOCK_GROUP_RAID10;

	else if (allowed & BTRFS_BLOCK_GROUP_RAID1)
	if (tmp & BTRFS_BLOCK_GROUP_RAID6)
		allowed = BTRFS_BLOCK_GROUP_RAID1;
		tmp = BTRFS_BLOCK_GROUP_RAID6;
	else if (allowed & BTRFS_BLOCK_GROUP_RAID0)
	else if (tmp & BTRFS_BLOCK_GROUP_RAID5)
		allowed = BTRFS_BLOCK_GROUP_RAID0;
		tmp = BTRFS_BLOCK_GROUP_RAID5;

	else if (tmp & BTRFS_BLOCK_GROUP_RAID10)
	flags &= ~BTRFS_BLOCK_GROUP_PROFILE_MASK;
		tmp = BTRFS_BLOCK_GROUP_RAID10;

	else if (tmp & BTRFS_BLOCK_GROUP_RAID1)
	return extended_to_chunk(flags | allowed);
		tmp = BTRFS_BLOCK_GROUP_RAID1;
	else if (tmp & BTRFS_BLOCK_GROUP_RAID0)
		tmp = BTRFS_BLOCK_GROUP_RAID0;

	return extended_to_chunk(flags | tmp);
}
}


static u64 get_alloc_profile(struct btrfs_root *root, u64 orig_flags)
static u64 get_alloc_profile(struct btrfs_root *root, u64 orig_flags)