Skip to contentSkip to conversation

enhance btrfs_raid_array[]

PATCH In review Anand Jain 3 participants 7 messages Apr 25, 2018 – Apr 27, 2018 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover enhance btrfs_raid_array[]

Cleanup patches as in the individual change log.

These patches were sent independently as they aren't related as such, but as I am updating the 1/3 the 2/3 would endup with conflict. So here I am putting all of them together with the conflict fixed at my end. And as such there is no change in 2/3 and 3/3 from its v1.

Anand Jain (3):
btrfs: kill btrfs_raid_type_names[]
btrfs: kill btrfs_raid_group[]
btrfs: kill btrfs_raid_mindev_error[]

 fs/btrfs/disk-io.c     |  2 +-
 fs/btrfs/extent-tree.c | 20 +------------------
 fs/btrfs/volumes.c     | 54 +++++++++++++++++++++++++++-----------------------
 fs/btrfs/volumes.h     |  7 +++++--
 4 files changed, 36 insertions(+), 47 deletions(-)
Signature · 1 line
2.7.0
author
#1 lore raw

PATCH v3 1/3 btrfs: kill btrfs_raid_type_names[]

Add a new member struct btrfs_raid_attr::raid_name so that btrfs_raid_array[] can maintain the name of the raid type, and so we can kill btrfs_raid_type_names[].

---
v2->v3:
use const char raid_name[8]
v1->v2:
add space after =. Such as..
+ .raid_name = "raid10",

 fs/btrfs/extent-tree.c | 18 ------------------
 fs/btrfs/volumes.c     | 15 +++++++++++++++
 fs/btrfs/volumes.h     |  3 +++
 3 files changed, 18 insertions(+), 18 deletions(-)
fs/btrfs/extent-tree.c +0 -18
index 90d28a3727c6..4742734a73d7 100644
@@ -7338,24 +7338,6 @@ wait_block_group_cache_done(struct btrfs_block_group_cache *cache)
 	return ret;
 }
 
-static const char *btrfs_raid_type_names[BTRFS_NR_RAID_TYPES] = {
-	[BTRFS_RAID_RAID10]	= "raid10",
-	[BTRFS_RAID_RAID1]	= "raid1",
-	[BTRFS_RAID_DUP]	= "dup",
-	[BTRFS_RAID_RAID0]	= "raid0",
-	[BTRFS_RAID_SINGLE]	= "single",
-	[BTRFS_RAID_RAID5]	= "raid5",
-	[BTRFS_RAID_RAID6]	= "raid6",
-};
-
-static const char *get_raid_name(enum btrfs_raid_types type)
-{
-	if (type >= BTRFS_NR_RAID_TYPES)
-		return NULL;
-
-	return btrfs_raid_type_names[type];
-}
-
 enum btrfs_loop_type {
 	LOOP_CACHING_NOWAIT = 0,
 	LOOP_CACHING_WAIT = 1,
fs/btrfs/volumes.c +15 -0
index 9c29fdca9075..5bb18ad6433d 100644
@@ -52,6 +52,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.tolerated_failures = 1,
 		.devs_increment	= 2,
 		.ncopies	= 2,
+		.raid_name	= "raid10",
 	},
 	[BTRFS_RAID_RAID1] = {
 		.sub_stripes	= 1,
@@ -61,6 +62,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.tolerated_failures = 1,
 		.devs_increment	= 2,
 		.ncopies	= 2,
+		.raid_name	= "raid1",
 	},
 	[BTRFS_RAID_DUP] = {
 		.sub_stripes	= 1,
@@ -70,6 +72,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.tolerated_failures = 0,
 		.devs_increment	= 1,
 		.ncopies	= 2,
+		.raid_name	= "dup",
 	},
 	[BTRFS_RAID_RAID0] = {
 		.sub_stripes	= 1,
@@ -79,6 +82,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.tolerated_failures = 0,
 		.devs_increment	= 1,
 		.ncopies	= 1,
+		.raid_name	= "raid0",
 	},
 	[BTRFS_RAID_SINGLE] = {
 		.sub_stripes	= 1,
@@ -88,6 +92,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.tolerated_failures = 0,
 		.devs_increment	= 1,
 		.ncopies	= 1,
+		.raid_name	= "single",
 	},
 	[BTRFS_RAID_RAID5] = {
 		.sub_stripes	= 1,
@@ -97,6 +102,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.tolerated_failures = 1,
 		.devs_increment	= 1,
 		.ncopies	= 2,
+		.raid_name	= "raid5",
 	},
 	[BTRFS_RAID_RAID6] = {
 		.sub_stripes	= 1,
@@ -106,9 +112,18 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.tolerated_failures = 2,
 		.devs_increment	= 1,
 		.ncopies	= 3,
+		.raid_name	= "raid6",
 	},
 };
 
+const char *get_raid_name(enum btrfs_raid_types type)
+{
+	if (type >= BTRFS_NR_RAID_TYPES)
+		return NULL;
+
+	return btrfs_raid_array[type].raid_name;
+}
+
 const u64 btrfs_raid_group[BTRFS_NR_RAID_TYPES] = {
 	[BTRFS_RAID_RAID10] = BTRFS_BLOCK_GROUP_RAID10,
 	[BTRFS_RAID_RAID1]  = BTRFS_BLOCK_GROUP_RAID1,
fs/btrfs/volumes.h +3 -0
index ef220d541d4b..d6edff847871 100644
@@ -342,6 +342,7 @@ struct btrfs_raid_attr {
 	int tolerated_failures; /* max tolerated fail devs */
 	int devs_increment;	/* ndevs has to be a multiple of this */
 	int ncopies;		/* how many copies to data has */
+	const char raid_name[8];/* name of the raid */
 };
 
 extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
@@ -563,6 +564,8 @@ static inline enum btrfs_raid_types btrfs_bg_flags_to_raid_index(u64 flags)
 	return BTRFS_RAID_SINGLE; /* BTRFS_BLOCK_GROUP_SINGLE */
 }
 
+const char *get_raid_name(enum btrfs_raid_types type);
+
 void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info);
 void btrfs_update_commit_device_bytes_used(struct btrfs_transaction *trans);
 
Signature · 1 line
2.7.0
author
#2 lore raw

PATCH 2/3 btrfs: kill btrfs_raid_group[]

In reply to Anand Jain

Add a new member struct btrfs_raid_attr::bg_flag so that btrfs_raid_array[] can maintain the bit map flag of the raid type, and so we can kill btrfs_raid_group[].

---
 fs/btrfs/disk-io.c     |  2 +-
 fs/btrfs/extent-tree.c |  2 +-
 fs/btrfs/volumes.c     | 19 ++++++++-----------
 fs/btrfs/volumes.h     |  2 +-
 4 files changed, 11 insertions(+), 14 deletions(-)
fs/btrfs/disk-io.c +1 -1
index b62559dfb053..2fa063c3ccec 100644
@@ -3525,7 +3525,7 @@ int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags)
 	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]))
+		if (!(flags & btrfs_raid_array[raid_type].bg_flag))
 			continue;
 		min_tolerated = min(min_tolerated,
 				    btrfs_raid_array[raid_type].
fs/btrfs/extent-tree.c +1 -1
index 4742734a73d7..19b4e24854ca 100644
@@ -4178,7 +4178,7 @@ static u64 btrfs_reduce_alloc_profile(struct btrfs_fs_info *fs_info, u64 flags)
 	/* First, mask out the RAID levels which aren't possible */
 	for (raid_type = 0; raid_type < BTRFS_NR_RAID_TYPES; raid_type++) {
 		if (num_devices >= btrfs_raid_array[raid_type].devs_min)
-			allowed |= btrfs_raid_group[raid_type];
+			allowed |= btrfs_raid_array[raid_type].bg_flag;
 	}
 	allowed &= flags;
 
fs/btrfs/volumes.c +8 -11
index 5bb18ad6433d..de3eea8b393e 100644
@@ -53,6 +53,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.devs_increment	= 2,
 		.ncopies	= 2,
 		.raid_name	= "raid10",
+		.bg_flag	= BTRFS_BLOCK_GROUP_RAID10,
 	},
 	[BTRFS_RAID_RAID1] = {
 		.sub_stripes	= 1,
@@ -63,6 +64,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.devs_increment	= 2,
 		.ncopies	= 2,
 		.raid_name	= "raid1",
+		.bg_flag	= BTRFS_BLOCK_GROUP_RAID1,
 	},
 	[BTRFS_RAID_DUP] = {
 		.sub_stripes	= 1,
@@ -73,6 +75,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.devs_increment	= 1,
 		.ncopies	= 2,
 		.raid_name	= "dup",
+		.bg_flag	= BTRFS_BLOCK_GROUP_DUP,
 	},
 	[BTRFS_RAID_RAID0] = {
 		.sub_stripes	= 1,
@@ -83,6 +86,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.devs_increment	= 1,
 		.ncopies	= 1,
 		.raid_name	= "raid0",
+		.bg_flag	= BTRFS_BLOCK_GROUP_RAID0,
 	},
 	[BTRFS_RAID_SINGLE] = {
 		.sub_stripes	= 1,
@@ -93,6 +97,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.devs_increment	= 1,
 		.ncopies	= 1,
 		.raid_name	= "single",
+		.bg_flag	= 0,
 	},
 	[BTRFS_RAID_RAID5] = {
 		.sub_stripes	= 1,
@@ -103,6 +108,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.devs_increment	= 1,
 		.ncopies	= 2,
 		.raid_name	= "raid5",
+		.bg_flag	= BTRFS_BLOCK_GROUP_RAID5,
 	},
 	[BTRFS_RAID_RAID6] = {
 		.sub_stripes	= 1,
@@ -113,6 +119,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.devs_increment	= 1,
 		.ncopies	= 3,
 		.raid_name	= "raid6",
+		.bg_flag	= BTRFS_BLOCK_GROUP_RAID6,
 	},
 };
 
@@ -124,16 +131,6 @@ const char *get_raid_name(enum btrfs_raid_types type)
 	return btrfs_raid_array[type].raid_name;
 }
 
-const u64 btrfs_raid_group[BTRFS_NR_RAID_TYPES] = {
-	[BTRFS_RAID_RAID10] = BTRFS_BLOCK_GROUP_RAID10,
-	[BTRFS_RAID_RAID1]  = BTRFS_BLOCK_GROUP_RAID1,
-	[BTRFS_RAID_DUP]    = BTRFS_BLOCK_GROUP_DUP,
-	[BTRFS_RAID_RAID0]  = BTRFS_BLOCK_GROUP_RAID0,
-	[BTRFS_RAID_SINGLE] = 0,
-	[BTRFS_RAID_RAID5]  = BTRFS_BLOCK_GROUP_RAID5,
-	[BTRFS_RAID_RAID6]  = BTRFS_BLOCK_GROUP_RAID6,
-};
-
 /*
  * Table to convert BTRFS_RAID_* to the error code if minimum number of devices
  * condition is not met. Zero means there's no corresponding
@@ -1898,7 +1895,7 @@ static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info,
 	} while (read_seqretry(&fs_info->profiles_lock, seq));
 
 	for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) {
-		if (!(all_avail & btrfs_raid_group[i]))
+		if (!(all_avail & btrfs_raid_array[i].bg_flag))
 			continue;
 
 		if (num_devices < btrfs_raid_array[i].devs_min) {
fs/btrfs/volumes.h +1 -1
index d6edff847871..d9c4c734d854 100644
@@ -343,11 +343,11 @@ struct btrfs_raid_attr {
 	int devs_increment;	/* ndevs has to be a multiple of this */
 	int ncopies;		/* how many copies to data has */
 	const char raid_name[8];/* name of the raid */
+	u64 bg_flag;		/* block group flag of the raid */
 };
 
 extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
 extern const int btrfs_raid_mindev_error[BTRFS_NR_RAID_TYPES];
-extern const u64 btrfs_raid_group[BTRFS_NR_RAID_TYPES];
 
 struct map_lookup {
 	u64 type;
Signature · 1 line
2.7.0
author
#3 lore raw

PATCH 3/3 btrfs: kill btrfs_raid_mindev_error[]

In reply to Anand Jain

Add a new member struct btrfs_raid_attr::mindev_error so that btrfs_raid_array[] can maintain the error code to return if the minimum numnber of devices required condition is not met while trying to delete a device in the given raid. And so we can kill btrfs_raid_mindev_error[].

---
 fs/btrfs/volumes.c | 24 ++++++++----------------
 fs/btrfs/volumes.h |  2 +-
 2 files changed, 9 insertions(+), 17 deletions(-)
fs/btrfs/volumes.c +8 -16
index de3eea8b393e..14efa98b7183 100644
@@ -54,6 +54,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.ncopies	= 2,
 		.raid_name	= "raid10",
 		.bg_flag	= BTRFS_BLOCK_GROUP_RAID10,
+		.mindev_error	= BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
 	},
 	[BTRFS_RAID_RAID1] = {
 		.sub_stripes	= 1,
@@ -65,6 +66,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.ncopies	= 2,
 		.raid_name	= "raid1",
 		.bg_flag	= BTRFS_BLOCK_GROUP_RAID1,
+		.mindev_error	= BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
 	},
 	[BTRFS_RAID_DUP] = {
 		.sub_stripes	= 1,
@@ -76,6 +78,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.ncopies	= 2,
 		.raid_name	= "dup",
 		.bg_flag	= BTRFS_BLOCK_GROUP_DUP,
+		.mindev_error	= 0,
 	},
 	[BTRFS_RAID_RAID0] = {
 		.sub_stripes	= 1,
@@ -87,6 +90,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.ncopies	= 1,
 		.raid_name	= "raid0",
 		.bg_flag	= BTRFS_BLOCK_GROUP_RAID0,
+		.mindev_error	= 0,
 	},
 	[BTRFS_RAID_SINGLE] = {
 		.sub_stripes	= 1,
@@ -98,6 +102,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.ncopies	= 1,
 		.raid_name	= "single",
 		.bg_flag	= 0,
+		.mindev_error	= 0,
 	},
 	[BTRFS_RAID_RAID5] = {
 		.sub_stripes	= 1,
@@ -109,6 +114,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.ncopies	= 2,
 		.raid_name	= "raid5",
 		.bg_flag	= BTRFS_BLOCK_GROUP_RAID5,
+		.mindev_error	= BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
 	},
 	[BTRFS_RAID_RAID6] = {
 		.sub_stripes	= 1,
@@ -120,6 +126,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = {
 		.ncopies	= 3,
 		.raid_name	= "raid6",
 		.bg_flag	= BTRFS_BLOCK_GROUP_RAID6,
+		.mindev_error	= BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
 	},
 };
 
@@ -131,21 +138,6 @@ const char *get_raid_name(enum btrfs_raid_types type)
 	return btrfs_raid_array[type].raid_name;
 }
 
-/*
- * Table to convert BTRFS_RAID_* to the error code if minimum number of devices
- * condition is not met. Zero means there's no corresponding
- * BTRFS_ERROR_DEV_*_NOT_MET value.
- */
-const int btrfs_raid_mindev_error[BTRFS_NR_RAID_TYPES] = {
-	[BTRFS_RAID_RAID10] = BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
-	[BTRFS_RAID_RAID1]  = BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
-	[BTRFS_RAID_DUP]    = 0,
-	[BTRFS_RAID_RAID0]  = 0,
-	[BTRFS_RAID_SINGLE] = 0,
-	[BTRFS_RAID_RAID5]  = BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
-	[BTRFS_RAID_RAID6]  = BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
-};
-
 static int init_first_rw_device(struct btrfs_trans_handle *trans,
 				struct btrfs_fs_info *fs_info);
 static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info);
@@ -1899,7 +1891,7 @@ static int btrfs_check_raid_min_devices(struct btrfs_fs_info *fs_info,
 			continue;
 
 		if (num_devices < btrfs_raid_array[i].devs_min) {
-			int ret = btrfs_raid_mindev_error[i];
+			int ret = btrfs_raid_array[i].mindev_error;
 
 			if (ret)
 				return ret;
fs/btrfs/volumes.h +1 -1
index d9c4c734d854..cc53a99116aa 100644
@@ -344,10 +344,10 @@ struct btrfs_raid_attr {
 	int ncopies;		/* how many copies to data has */
 	const char raid_name[8];/* name of the raid */
 	u64 bg_flag;		/* block group flag of the raid */
+	int mindev_error;	/* error code if min devs requisite is unmet */
 };
 
 extern const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES];
-extern const int btrfs_raid_mindev_error[BTRFS_NR_RAID_TYPES];
 
 struct map_lookup {
 	u64 type;
Signature · 1 line
2.7.0
Reviewed-by on the v1 series
#4 lore raw
In reply to Anand Jain
Quoted 12 lines · Anand Jain

Cleanup patches as in the individual change log.

These patches were sent independently as they aren't related as such, but as I am updating the 1/3 the 2/3 would endup with conflict. So here I am putting all of them together with the conflict fixed at my end. And as such there is no change in 2/3 and 3/3 from its v1.

Anand Jain (3):
btrfs: kill btrfs_raid_type_names[]
btrfs: kill btrfs_raid_group[]
btrfs: kill btrfs_raid_mindev_error[]

Quoted 6 lines
 fs/btrfs/disk-io.c     |  2 +-
 fs/btrfs/extent-tree.c | 20 +------------------
 fs/btrfs/volumes.c     | 54 +++++++++++++++++++++++++++-----------------------
 fs/btrfs/volumes.h     |  7 +++++--
 4 files changed, 36 insertions(+), 47 deletions(-)

For the whole series:

#5 lore raw
In reply to Anand Jain
Quoted 11 lines · Anand Jain

Cleanup patches as in the individual change log.

These patches were sent independently as they aren't related as such, but as I am updating the 1/3 the 2/3 would endup with conflict. So here I am putting all of them together with the conflict fixed at my end. And as such there is no change in 2/3 and 3/3 from its v1.

Anand Jain (3):
btrfs: kill btrfs_raid_type_names[]
btrfs: kill btrfs_raid_group[]
btrfs: kill btrfs_raid_mindev_error[]

Added to misc-next, thanks. I've reordered the mindev_error before the raid_name for better struct packing.

author
#6 lore raw
Quoted 13 lines · David Sterba
Quoted 11 lines · Anand Jain

Cleanup patches as in the individual change log.

These patches were sent independently as they aren't related as such, but as I am updating the 1/3 the 2/3 would endup with conflict. So here I am putting all of them together with the conflict fixed at my end. And as such there is no change in 2/3 and 3/3 from its v1.

Anand Jain (3):

   btrfs: kill btrfs_raid_type_names[]
   btrfs: kill btrfs_raid_group[]
   btrfs: kill btrfs_raid_mindev_error[]
Quoted 4 lines

Added to misc-next, thanks.

I've reordered the mindev_error before the
raid_name for better struct packing.

Right. Thanks.

-Anand

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html