Skip to contentSkip to conversation

Preparatory to add read_mirror mount option

PATCH Superseded Anand Jain 3 participants 7 messages Jan 30, 2018 – Feb 24, 2018 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover Preparatory to add read_mirror mount option

Adds cleanups to find_live_mirror(), so that we can add more policy on how the read mirror device should be found.

Anand Jain (2):
btrfs: drop num argument from find_live_mirror()
btrfs: drop optimal argument from find_live_mirror()

 fs/btrfs/volumes.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
Signature · 1 line
2.7.0
author
#1 lore raw

PATCH 1/2 btrfs: drop num argument from find_live_mirror()

Obtain the stripes info from the map directly and so no need to pass it as an argument.

---
 fs/btrfs/volumes.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
fs/btrfs/volumes.c +11 -3
index f7147740b68e..9c9d987838c2 100644
@@ -5252,13 +5252,22 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
 }
 
 static int find_live_mirror(struct btrfs_fs_info *fs_info,
-			    struct map_lookup *map, int first, int num,
+			    struct map_lookup *map, int first,
 			    int optimal, int dev_replace_is_ongoing)
 {
 	int i;
+	int num;
 	int tolerance;
 	struct btrfs_device *srcdev;
 
+	ASSERT((map->type &
+		 (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10)));
+
+	if (map->type & BTRFS_BLOCK_GROUP_RAID10)
+		num = map->sub_stripes;
+	else
+		num = map->num_stripes;
+
 	if (dev_replace_is_ongoing &&
 	    fs_info->dev_replace.cont_reading_from_srcdev_mode ==
 	     BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID)
@@ -5812,7 +5821,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			stripe_index = mirror_num - 1;
 		else {
 			stripe_index = find_live_mirror(fs_info, map, 0,
-					    map->num_stripes,
 					    current->pid % map->num_stripes,
 					    dev_replace_is_ongoing);
 			mirror_num = stripe_index + 1;
@@ -5841,7 +5849,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			int old_stripe_index = stripe_index;
 			stripe_index = find_live_mirror(fs_info, map,
 					      stripe_index,
-					      map->sub_stripes, stripe_index +
+					      stripe_index +
 					      current->pid % map->sub_stripes,
 					      dev_replace_is_ongoing);
 			mirror_num = stripe_index - old_stripe_index + 1;
Signature · 1 line
2.7.0
#2 lore raw

Re: [PATCH 1/2] btrfs: drop num argument from find_live_mirror()

Quoted 13 lines · Anand Jain

Obtain the stripes info from the map directly and so no need to pass it as an argument.

---
 fs/btrfs/volumes.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
fs/btrfs/volumes.c +0 -0
index f7147740b68e..9c9d987838c2 100644

fs/btrfs/volumes.c int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len) · line 5259

Quoted 9 lines
fs/btrfs/volumes.c +2 -1
@@ -5252,13 +5252,22 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
 }
 
 static int find_live_mirror(struct btrfs_fs_info *fs_info,
-			    struct map_lookup *map, int first, int num,
+			    struct map_lookup *map, int first,
 			    int optimal, int dev_replace_is_ongoing)
 {
 	int i;
+	int num;

Can you please rename it to something more descriptive? Eg. num_stripes.

Quoted 38 lines
fs/btrfs/volumes.c +9 -2
 	int tolerance;
 	struct btrfs_device *srcdev;
 
+	ASSERT((map->type &
+		 (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10)));
+
+	if (map->type & BTRFS_BLOCK_GROUP_RAID10)
+		num = map->sub_stripes;
+	else
+		num = map->num_stripes;
+
 	if (dev_replace_is_ongoing &&
 	    fs_info->dev_replace.cont_reading_from_srcdev_mode ==
 	     BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID)
@@ -5812,7 +5821,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			stripe_index = mirror_num - 1;
 		else {
 			stripe_index = find_live_mirror(fs_info, map, 0,
-					    map->num_stripes,
 					    current->pid % map->num_stripes,
 					    dev_replace_is_ongoing);
 			mirror_num = stripe_index + 1;
@@ -5841,7 +5849,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			int old_stripe_index = stripe_index;
 			stripe_index = find_live_mirror(fs_info, map,
 					      stripe_index,
-					      map->sub_stripes, stripe_index +
+					      stripe_index +
 					      current->pid % map->sub_stripes,
 					      dev_replace_is_ongoing);
 			mirror_num = stripe_index - old_stripe_index + 1;
Signature · 6 lines
2.7.0

--
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
author
#3 lore raw

PATCH 2/2 btrfs: drop optimal argument from find_live_mirror()

In reply to Anand Jain

Drop optimal argument from the function find_live_mirror() as we can deduce it in the function itself.

---
 fs/btrfs/volumes.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +4 -4
index 9c9d987838c2..a61715677b67 100644
@@ -5253,10 +5253,11 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
 
 static int find_live_mirror(struct btrfs_fs_info *fs_info,
 			    struct map_lookup *map, int first,
-			    int optimal, int dev_replace_is_ongoing)
+			    int dev_replace_is_ongoing)
 {
 	int i;
 	int num;
+	int optimal;
 	int tolerance;
 	struct btrfs_device *srcdev;
 
@@ -5268,6 +5269,8 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
 	else
 		num = map->num_stripes;
 
+	optimal = first + current->pid % num;
+
 	if (dev_replace_is_ongoing &&
 	    fs_info->dev_replace.cont_reading_from_srcdev_mode ==
 	     BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID)
@@ -5821,7 +5824,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			stripe_index = mirror_num - 1;
 		else {
 			stripe_index = find_live_mirror(fs_info, map, 0,
-					    current->pid % map->num_stripes,
 					    dev_replace_is_ongoing);
 			mirror_num = stripe_index + 1;
 		}
@@ -5849,8 +5851,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			int old_stripe_index = stripe_index;
 			stripe_index = find_live_mirror(fs_info, map,
 					      stripe_index,
-					      stripe_index +
-					      current->pid % map->sub_stripes,
 					      dev_replace_is_ongoing);
 			mirror_num = stripe_index - old_stripe_index + 1;
 		}
Signature · 1 line
2.7.0
#4 lore raw

Re: [PATCH 2/2] btrfs: drop optimal argument from find_live_mirror()

Quoted 43 lines · Anand Jain

Drop optimal argument from the function find_live_mirror() as we can deduce it in the function itself.

---
 fs/btrfs/volumes.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +4 -2
index 9c9d987838c2..a61715677b67 100644
@@ -5253,10 +5253,11 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
 
 static int find_live_mirror(struct btrfs_fs_info *fs_info,
 			    struct map_lookup *map, int first,
-			    int optimal, int dev_replace_is_ongoing)
+			    int dev_replace_is_ongoing)
 {
 	int i;
 	int num;
+	int optimal;
 	int tolerance;
 	struct btrfs_device *srcdev;
 
@@ -5268,6 +5269,8 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
 	else
 		num = map->num_stripes;
 
+	optimal = first + current->pid % num;
+
 	if (dev_replace_is_ongoing &&
 	    fs_info->dev_replace.cont_reading_from_srcdev_mode ==
 	     BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID)
@@ -5821,7 +5824,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			stripe_index = mirror_num - 1;
 		else {
 			stripe_index = find_live_mirror(fs_info, map, 0,
-					    current->pid % map->num_stripes,
 					    dev_replace_is_ongoing);
 			mirror_num = stripe_index + 1;
 		}

fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, · line 5853

Quoted 5 lines
fs/btrfs/volumes.c +0 -2
@@ -5849,8 +5851,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
 			int old_stripe_index = stripe_index;
 			stripe_index = find_live_mirror(fs_info, map,
 					      stripe_index,
-					      stripe_index +
-					      current->pid % map->sub_stripes,

The value of optimal here (BTRFS_BLOCK_GROUP_RAID10) is different than the value of optimal in BTRFS_BLOCK_GROUP_RAID1 case. So you need to put optimal in the conditional branch you added in the previous patch. In raid 1 case:

optimal = current->pid % num;

In raid 10:

optimal = first + current->pid % num;

to current semantics

Quoted 4 lines
fs/btrfs/volumes.c +0 -0
 					      dev_replace_is_ongoing);
 			mirror_num = stripe_index - old_stripe_index + 1;
 		}
author
#5 lore raw

Re: [PATCH 2/2] btrfs: drop optimal argument from find_live_mirror()

Quoted 57 lines · Nikolay Borisov
Quoted 43 lines · Anand Jain

Drop optimal argument from the function find_live_mirror() as we can deduce it in the function itself.

---
  fs/btrfs/volumes.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +4 -2
index 9c9d987838c2..a61715677b67 100644
@@ -5253,10 +5253,11 @@ int btrfs_is_parity_mirror(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
 
  static int find_live_mirror(struct btrfs_fs_info *fs_info,
  			    struct map_lookup *map, int first,
-			    int optimal, int dev_replace_is_ongoing)
+			    int dev_replace_is_ongoing)
  {
  	int i;
  	int num;
+	int optimal;
  	int tolerance;
  	struct btrfs_device *srcdev;
 
@@ -5268,6 +5269,8 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
  	else
  		num = map->num_stripes;
 
+	optimal = first + current->pid % num;
+
  	if (dev_replace_is_ongoing &&
  	    fs_info->dev_replace.cont_reading_from_srcdev_mode ==
  	     BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID)
@@ -5821,7 +5824,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
  			stripe_index = mirror_num - 1;
  		else {
  			stripe_index = find_live_mirror(fs_info, map, 0,
-					    current->pid % map->num_stripes,
  					    dev_replace_is_ongoing);
  			mirror_num = stripe_index + 1;
  		}

fs/btrfs/volumes.c static int __btrfs_map_block(struct btrfs_fs_info *fs_info, · line 5853

Quoted 5 lines
fs/btrfs/volumes.c +0 -2
@@ -5849,8 +5851,6 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
  			int old_stripe_index = stripe_index;
  			stripe_index = find_live_mirror(fs_info, map,
  					      stripe_index,
-					      stripe_index +
-					      current->pid % map->sub_stripes,

The value of optimal here (BTRFS_BLOCK_GROUP_RAID10) is different than the value of optimal in BTRFS_BLOCK_GROUP_RAID1 case. So you need to put optimal in the conditional branch you added in the previous patch. In raid 1 case:

Quoted 7 lines

optimal = current->pid % num;

In raid 10:

optimal = first + current->pid % num;

to current semantics

First/stripe_index is 0 for RAID1. So I purposely kept it like this
for easy code flow.

Thanks, Anand

Quoted 4 lines
Quoted 4 lines
fs/btrfs/volumes.c +0 -0
  					      dev_replace_is_ongoing);
  			mirror_num = stripe_index - old_stripe_index + 1;
  		}
#6 lore raw

Re: [PATCH 2/2] btrfs: drop optimal argument from find_live_mirror()

In reply to Anand Jain
Quoted 2 lines · Anand Jain

Drop optimal argument from the function find_live_mirror() as we can deduce it in the function itself.

Yeah the argument is not necessary. It's another misleading variable name, as it's not 'optimal' but a fallback. Please rename it.