linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Preparatory to add read_mirror mount option
@ 2018-01-30  6:28 Anand Jain
  2018-01-30  6:28 ` [PATCH 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
  2018-01-30  6:28 ` [PATCH 2/2] btrfs: drop optimal " Anand Jain
  0 siblings, 2 replies; 7+ messages in thread
From: Anand Jain @ 2018-01-30  6:28 UTC (permalink / raw)
  To: linux-btrfs

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(-)

-- 
2.7.0


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

* [PATCH 1/2] btrfs: drop num argument from find_live_mirror()
  2018-01-30  6:28 [PATCH 0/2] Preparatory to add read_mirror mount option Anand Jain
@ 2018-01-30  6:28 ` Anand Jain
  2018-02-24  0:26   ` David Sterba
  2018-01-30  6:28 ` [PATCH 2/2] btrfs: drop optimal " Anand Jain
  1 sibling, 1 reply; 7+ messages in thread
From: Anand Jain @ 2018-01-30  6:28 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>
---
 fs/btrfs/volumes.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index f7147740b68e..9c9d987838c2 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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;
-- 
2.7.0


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

* [PATCH 2/2] btrfs: drop optimal argument from find_live_mirror()
  2018-01-30  6:28 [PATCH 0/2] Preparatory to add read_mirror mount option Anand Jain
  2018-01-30  6:28 ` [PATCH 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
@ 2018-01-30  6:28 ` Anand Jain
  2018-01-30  9:12   ` Nikolay Borisov
  2018-02-24  0:28   ` David Sterba
  1 sibling, 2 replies; 7+ messages in thread
From: Anand Jain @ 2018-01-30  6:28 UTC (permalink / raw)
  To: linux-btrfs

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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/volumes.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 9c9d987838c2..a61715677b67 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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;
 		}
-- 
2.7.0


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

* Re: [PATCH 2/2] btrfs: drop optimal argument from find_live_mirror()
  2018-01-30  6:28 ` [PATCH 2/2] btrfs: drop optimal " Anand Jain
@ 2018-01-30  9:12   ` Nikolay Borisov
  2018-01-30 10:04     ` Anand Jain
  2018-02-24  0:28   ` David Sterba
  1 sibling, 1 reply; 7+ messages in thread
From: Nikolay Borisov @ 2018-01-30  9:12 UTC (permalink / raw)
  To: Anand Jain, linux-btrfs



On 30.01.2018 08:28, Anand Jain wrote:
> Drop optimal argument from the function find_live_mirror()
> as we can deduce it in the function itself.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  fs/btrfs/volumes.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 9c9d987838c2..a61715677b67 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -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,

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

>  					      dev_replace_is_ongoing);
>  			mirror_num = stripe_index - old_stripe_index + 1;
>  		}
> 

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

* Re: [PATCH 2/2] btrfs: drop optimal argument from find_live_mirror()
  2018-01-30  9:12   ` Nikolay Borisov
@ 2018-01-30 10:04     ` Anand Jain
  0 siblings, 0 replies; 7+ messages in thread
From: Anand Jain @ 2018-01-30 10:04 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs



On 01/30/2018 05:12 PM, Nikolay Borisov wrote:
> 
> 
> On 30.01.2018 08:28, Anand Jain wrote:
>> Drop optimal argument from the function find_live_mirror()
>> as we can deduce it in the function itself.
>>
>> Signed-off-by: Anand Jain <anand.jain@oracle.com>
>> ---
>>   fs/btrfs/volumes.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index 9c9d987838c2..a61715677b67 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -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,
> 
> 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

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

Thanks, Anand

>>   					      dev_replace_is_ongoing);
>>   			mirror_num = stripe_index - old_stripe_index + 1;
>>   		}
>>

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

* Re: [PATCH 1/2] btrfs: drop num argument from find_live_mirror()
  2018-01-30  6:28 ` [PATCH 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
@ 2018-02-24  0:26   ` David Sterba
  0 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2018-02-24  0:26 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Tue, Jan 30, 2018 at 02:28:30PM +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>
> ---
>  fs/btrfs/volumes.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index f7147740b68e..9c9d987838c2 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -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.

>  	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;
> -- 
> 2.7.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/2] btrfs: drop optimal argument from find_live_mirror()
  2018-01-30  6:28 ` [PATCH 2/2] btrfs: drop optimal " Anand Jain
  2018-01-30  9:12   ` Nikolay Borisov
@ 2018-02-24  0:28   ` David Sterba
  1 sibling, 0 replies; 7+ messages in thread
From: David Sterba @ 2018-02-24  0:28 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Tue, Jan 30, 2018 at 02:28:31PM +0800, Anand Jain wrote:
> 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.

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

end of thread, other threads:[~2018-02-24  0:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-30  6:28 [PATCH 0/2] Preparatory to add read_mirror mount option Anand Jain
2018-01-30  6:28 ` [PATCH 1/2] btrfs: drop num argument from find_live_mirror() Anand Jain
2018-02-24  0:26   ` David Sterba
2018-01-30  6:28 ` [PATCH 2/2] btrfs: drop optimal " Anand Jain
2018-01-30  9:12   ` Nikolay Borisov
2018-01-30 10:04     ` Anand Jain
2018-02-24  0:28   ` 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).