linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] btrfs: drop num argument from find_live_mirror()
@ 2018-03-14  8:29 Anand Jain
  2018-03-14  8:29 ` [PATCH v2 2/2] btrfs: drop optimal " Anand Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Anand Jain @ 2018-03-14  8:29 UTC (permalink / raw)
  To: linux-btrfs

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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v1->v2:
  Accepts David's comment to rename %num to %num_stripes.

 fs/btrfs/volumes.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1e72357bdfa8..9beea7c891a7 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5275,13 +5275,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_stripes;
 	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_stripes = map->sub_stripes;
+	else
+		num_stripes = 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)
@@ -5298,7 +5307,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
 		if (map->stripes[optimal].dev->bdev &&
 		    (tolerance || map->stripes[optimal].dev != srcdev))
 			return optimal;
-		for (i = first; i < first + num; i++) {
+		for (i = first; i < first + num_stripes; i++) {
 			if (map->stripes[i].dev->bdev &&
 			    (tolerance || map->stripes[i].dev != srcdev))
 				return i;
@@ -5835,7 +5844,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;
@@ -5864,7 +5872,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;
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] btrfs: drop optimal argument from find_live_mirror()
  2018-03-14  8:29 [PATCH v2 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
@ 2018-03-14  8:29 ` Anand Jain
  2018-03-14  9:24   ` Nikolay Borisov
  2018-03-14  9:22 ` [PATCH v2 1/2] btrfs: drop num " Nikolay Borisov
  2018-03-16 16:30 ` David Sterba
  2 siblings, 1 reply; 5+ messages in thread
From: Anand Jain @ 2018-03-14  8:29 UTC (permalink / raw)
  To: linux-btrfs

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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
I thought I have sent v2 to the ML. But now I realize I didn't.
v1->v2:
   Accepts David's comment to rename %optimal. IMO, %preferred_mirror is
   better than the suggested %fallback.

 fs/btrfs/volumes.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9beea7c891a7..f1b7efbdcec1 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5276,10 +5276,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_stripes;
+	int preferred_mirror;
 	int tolerance;
 	struct btrfs_device *srcdev;
 
@@ -5291,6 +5292,8 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
 	else
 		num_stripes = map->num_stripes;
 
+	preferred_mirror = first + current->pid % 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)
@@ -5304,9 +5307,9 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
 	 * mirror is available
 	 */
 	for (tolerance = 0; tolerance < 2; tolerance++) {
-		if (map->stripes[optimal].dev->bdev &&
-		    (tolerance || map->stripes[optimal].dev != srcdev))
-			return optimal;
+		if (map->stripes[preferred_mirror].dev->bdev &&
+		    (tolerance || map->stripes[preferred_mirror].dev != srcdev))
+			return preferred_mirror;
 		for (i = first; i < first + num_stripes; i++) {
 			if (map->stripes[i].dev->bdev &&
 			    (tolerance || map->stripes[i].dev != srcdev))
@@ -5317,7 +5320,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
 	/* we couldn't find one that doesn't fail.  Just return something
 	 * and the io error handling code will clean up eventually
 	 */
-	return optimal;
+	return preferred_mirror;
 }
 
 static inline int parity_smaller(u64 a, u64 b)
@@ -5844,7 +5847,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;
 		}
@@ -5872,8 +5874,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;
 		}
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] btrfs: drop num argument from find_live_mirror()
  2018-03-14  8:29 [PATCH v2 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
  2018-03-14  8:29 ` [PATCH v2 2/2] btrfs: drop optimal " Anand Jain
@ 2018-03-14  9:22 ` Nikolay Borisov
  2018-03-16 16:30 ` David Sterba
  2 siblings, 0 replies; 5+ messages in thread
From: Nikolay Borisov @ 2018-03-14  9:22 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs



On 14.03.2018 10:29, Anand Jain wrote:
> Obtain the stripes info from the map directly and so no need
> to pass it as an argument.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

LGTM

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
> v1->v2:
>   Accepts David's comment to rename %num to %num_stripes.
> 
>  fs/btrfs/volumes.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 1e72357bdfa8..9beea7c891a7 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5275,13 +5275,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_stripes;
>  	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_stripes = map->sub_stripes;
> +	else
> +		num_stripes = 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)
> @@ -5298,7 +5307,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
>  		if (map->stripes[optimal].dev->bdev &&
>  		    (tolerance || map->stripes[optimal].dev != srcdev))
>  			return optimal;
> -		for (i = first; i < first + num; i++) {
> +		for (i = first; i < first + num_stripes; i++) {
>  			if (map->stripes[i].dev->bdev &&
>  			    (tolerance || map->stripes[i].dev != srcdev))
>  				return i;
> @@ -5835,7 +5844,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;
> @@ -5864,7 +5872,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;
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] btrfs: drop optimal argument from find_live_mirror()
  2018-03-14  8:29 ` [PATCH v2 2/2] btrfs: drop optimal " Anand Jain
@ 2018-03-14  9:24   ` Nikolay Borisov
  0 siblings, 0 replies; 5+ messages in thread
From: Nikolay Borisov @ 2018-03-14  9:24 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs



On 14.03.2018 10:29, Anand Jain wrote:
> Drop optimal argument from the function find_live_mirror()
> as we can deduce it in the function itself. Also rename
> optimal to preferred_mirror.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
> I thought I have sent v2 to the ML. But now I realize I didn't.
> v1->v2:
>    Accepts David's comment to rename %optimal. IMO, %preferred_mirror is
>    better than the suggested %fallback.
> 
>  fs/btrfs/volumes.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 9beea7c891a7..f1b7efbdcec1 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5276,10 +5276,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_stripes;
> +	int preferred_mirror;
>  	int tolerance;
>  	struct btrfs_device *srcdev;
>  
> @@ -5291,6 +5292,8 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
>  	else
>  		num_stripes = map->num_stripes;
>  
> +	preferred_mirror = first + current->pid % 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)
> @@ -5304,9 +5307,9 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
>  	 * mirror is available
>  	 */
>  	for (tolerance = 0; tolerance < 2; tolerance++) {
> -		if (map->stripes[optimal].dev->bdev &&
> -		    (tolerance || map->stripes[optimal].dev != srcdev))
> -			return optimal;
> +		if (map->stripes[preferred_mirror].dev->bdev &&
> +		    (tolerance || map->stripes[preferred_mirror].dev != srcdev))
> +			return preferred_mirror;
>  		for (i = first; i < first + num_stripes; i++) {
>  			if (map->stripes[i].dev->bdev &&
>  			    (tolerance || map->stripes[i].dev != srcdev))
> @@ -5317,7 +5320,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
>  	/* we couldn't find one that doesn't fail.  Just return something
>  	 * and the io error handling code will clean up eventually
>  	 */
> -	return optimal;
> +	return preferred_mirror;
>  }
>  
>  static inline int parity_smaller(u64 a, u64 b)
> @@ -5844,7 +5847,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;
>  		}
> @@ -5872,8 +5874,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;
>  		}
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] btrfs: drop num argument from find_live_mirror()
  2018-03-14  8:29 [PATCH v2 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
  2018-03-14  8:29 ` [PATCH v2 2/2] btrfs: drop optimal " Anand Jain
  2018-03-14  9:22 ` [PATCH v2 1/2] btrfs: drop num " Nikolay Borisov
@ 2018-03-16 16:30 ` David Sterba
  2 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2018-03-16 16:30 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Wed, Mar 14, 2018 at 04:29:12PM +0800, Anand Jain wrote:
> Obtain the stripes info from the map directly and so no need
> to pass it as an argument.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

1-2 applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-16 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-14  8:29 [PATCH v2 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
2018-03-14  8:29 ` [PATCH v2 2/2] btrfs: drop optimal " Anand Jain
2018-03-14  9:24   ` Nikolay Borisov
2018-03-14  9:22 ` [PATCH v2 1/2] btrfs: drop num " Nikolay Borisov
2018-03-16 16:30 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).