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

Commit 8789f4fe authored by Zhao Lei's avatar Zhao Lei Committed by David Sterba
Browse files

btrfs: use btrfs_raid_array for btrfs_get_num_tolerated_disk_barrier_failures()



btrfs_raid_array[] is used to define all raid attributes, use it
to get tolerated_failures in btrfs_get_num_tolerated_disk_barrier_failures(),
instead of complex condition in function.

It can make code simple and auto-support other possible raid-type in
future.

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 af902047
Loading
Loading
Loading
Loading
+22 −13
Original line number Original line Diff line number Diff line
@@ -3449,22 +3449,31 @@ static int barrier_all_devices(struct btrfs_fs_info *info)


int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags)
int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags)
{
{
	if ((flags & (BTRFS_BLOCK_GROUP_DUP |
	int raid_type;
		      BTRFS_BLOCK_GROUP_RAID0 |
	int min_tolerated = INT_MAX;
		      BTRFS_AVAIL_ALLOC_BIT_SINGLE)) ||
	    ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0))
		return 0;


	if (flags & (BTRFS_BLOCK_GROUP_RAID1 |
	if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 ||
		     BTRFS_BLOCK_GROUP_RAID5 |
	    (flags & BTRFS_AVAIL_ALLOC_BIT_SINGLE))
		     BTRFS_BLOCK_GROUP_RAID10))
		min_tolerated = min(min_tolerated,
		return 1;
				    btrfs_raid_array[BTRFS_RAID_SINGLE].
				    tolerated_failures);

	for (raid_type = 0; raid_type < BTRFS_NR_RAID_TYPES; raid_type++) {
		if (raid_type == BTRFS_RAID_SINGLE)
			continue;
		if (!(flags & btrfs_raid_group[raid_type]))
			continue;
		min_tolerated = min(min_tolerated,
				    btrfs_raid_array[raid_type].
				    tolerated_failures);
	}


	if (flags & BTRFS_BLOCK_GROUP_RAID6)
	if (min_tolerated == INT_MAX) {
		return 2;
		pr_warn("BTRFS: unknown raid flag: %llu\n", flags);
		min_tolerated = 0;
	}


	pr_warn("BTRFS: unknown raid type: %llu\n", flags);
	return min_tolerated;
	return 0;
}
}


int btrfs_calc_num_tolerated_disk_barrier_failures(
int btrfs_calc_num_tolerated_disk_barrier_failures(
+7 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
		.dev_stripes	= 1,
		.dev_stripes	= 1,
		.devs_max	= 0,	/* 0 == as many as possible */
		.devs_max	= 0,	/* 0 == as many as possible */
		.devs_min	= 4,
		.devs_min	= 4,
		.tolerated_failures = 1,
		.devs_increment	= 2,
		.devs_increment	= 2,
		.ncopies	= 2,
		.ncopies	= 2,
	},
	},
@@ -56,6 +57,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
		.dev_stripes	= 1,
		.dev_stripes	= 1,
		.devs_max	= 2,
		.devs_max	= 2,
		.devs_min	= 2,
		.devs_min	= 2,
		.tolerated_failures = 1,
		.devs_increment	= 2,
		.devs_increment	= 2,
		.ncopies	= 2,
		.ncopies	= 2,
	},
	},
@@ -64,6 +66,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
		.dev_stripes	= 2,
		.dev_stripes	= 2,
		.devs_max	= 1,
		.devs_max	= 1,
		.devs_min	= 1,
		.devs_min	= 1,
		.tolerated_failures = 0,
		.devs_increment	= 1,
		.devs_increment	= 1,
		.ncopies	= 2,
		.ncopies	= 2,
	},
	},
@@ -72,6 +75,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
		.dev_stripes	= 1,
		.dev_stripes	= 1,
		.devs_max	= 0,
		.devs_max	= 0,
		.devs_min	= 2,
		.devs_min	= 2,
		.tolerated_failures = 0,
		.devs_increment	= 1,
		.devs_increment	= 1,
		.ncopies	= 1,
		.ncopies	= 1,
	},
	},
@@ -80,6 +84,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
		.dev_stripes	= 1,
		.dev_stripes	= 1,
		.devs_max	= 1,
		.devs_max	= 1,
		.devs_min	= 1,
		.devs_min	= 1,
		.tolerated_failures = 0,
		.devs_increment	= 1,
		.devs_increment	= 1,
		.ncopies	= 1,
		.ncopies	= 1,
	},
	},
@@ -88,6 +93,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
		.dev_stripes	= 1,
		.dev_stripes	= 1,
		.devs_max	= 0,
		.devs_max	= 0,
		.devs_min	= 2,
		.devs_min	= 2,
		.tolerated_failures = 1,
		.devs_increment	= 1,
		.devs_increment	= 1,
		.ncopies	= 2,
		.ncopies	= 2,
	},
	},
@@ -96,6 +102,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
		.dev_stripes	= 1,
		.dev_stripes	= 1,
		.devs_max	= 0,
		.devs_max	= 0,
		.devs_min	= 3,
		.devs_min	= 3,
		.tolerated_failures = 2,
		.devs_increment	= 1,
		.devs_increment	= 1,
		.ncopies	= 3,
		.ncopies	= 3,
	},
	},
+1 −0
Original line number Original line Diff line number Diff line
@@ -334,6 +334,7 @@ struct btrfs_raid_attr {
	int dev_stripes;	/* stripes per dev */
	int dev_stripes;	/* stripes per dev */
	int devs_max;		/* max devs to use */
	int devs_max;		/* max devs to use */
	int devs_min;		/* min devs needed */
	int devs_min;		/* min devs needed */
	int tolerated_failures; /* max tolerated fail devs */
	int devs_increment;	/* ndevs has to be a multiple of this */
	int devs_increment;	/* ndevs has to be a multiple of this */
	int ncopies;		/* how many copies to data has */
	int ncopies;		/* how many copies to data has */
};
};