All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] super1: fix sb->max_dev when adding a new disk in linear array
@ 2017-05-19  6:06 Lidong Zhong
  2017-05-21 23:31 ` NeilBrown
  0 siblings, 1 reply; 4+ messages in thread
From: Lidong Zhong @ 2017-05-19  6:06 UTC (permalink / raw)
  To: linux-raid, neilb; +Cc: colyli, Jes.Sorensen

The value of sb->max_dev will always be increased by 1 when adding
a new disk in linear array. It causes an inconsistence between each
disk in the array and the "Array State" value of "mdadm --examine DISK"
is wrong. For example, when adding the first new disk into linear array
it will be:

Array State : RAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
('A' == active, '.' == missing, 'R' == replacing)

Adding the second disk into linear array it will be

Array State : .AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
('A' == active, '.' == missing, 'R' == replacing)

Signed-off-by: Lidong Zhong <lzhong@suse.com>
---
 super1.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/super1.c b/super1.c
index 2fcb814..811923f 100644
--- a/super1.c
+++ b/super1.c
@@ -1267,8 +1267,13 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
 				break;
 		sb->dev_number = __cpu_to_le32(i);
 		info->disk.number = i;
-		if (max >= __le32_to_cpu(sb->max_dev))
-			sb->max_dev = __cpu_to_le32(max+1);
+		if (i >= max) {
+			while (max <= i) {
+				sb->dev_roles[max] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
+				max += 1;
+			}
+			sb->max_dev = __cpu_to_le32(max);
+		}
 
 		random_uuid(sb->device_uuid);
 
@@ -1296,6 +1301,10 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
 		sb->raid_disks = __cpu_to_le32(info->array.raid_disks);
 		sb->dev_roles[info->disk.number] =
 			__cpu_to_le16(info->disk.raid_disk);
+		if (sb->raid_disks+1 >= __le32_to_cpu(sb->max_dev)) {
+			sb->dev_roles[sb->raid_disks] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
+			sb->max_dev = __cpu_to_le32(sb->raid_disks+1);
+		}
 	} else if (strcmp(update, "resync") == 0) {
 		/* make sure resync happens */
 		sb->resync_offset = 0ULL;
-- 
2.12.0


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

* Re: [PATCH v3] super1: fix sb->max_dev when adding a new disk in linear array
  2017-05-19  6:06 [PATCH v3] super1: fix sb->max_dev when adding a new disk in linear array Lidong Zhong
@ 2017-05-21 23:31 ` NeilBrown
  2017-05-22  3:28   ` Lidong Zhong
  0 siblings, 1 reply; 4+ messages in thread
From: NeilBrown @ 2017-05-21 23:31 UTC (permalink / raw)
  To: Lidong Zhong, linux-raid; +Cc: colyli, Jes.Sorensen

[-- Attachment #1: Type: text/plain, Size: 2190 bytes --]

On Fri, May 19 2017, Lidong Zhong wrote:

> The value of sb->max_dev will always be increased by 1 when adding
> a new disk in linear array. It causes an inconsistence between each
> disk in the array and the "Array State" value of "mdadm --examine DISK"
> is wrong. For example, when adding the first new disk into linear array
> it will be:
>
> Array State : RAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
> ('A' == active, '.' == missing, 'R' == replacing)
>
> Adding the second disk into linear array it will be
>
> Array State : .AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
> ('A' == active, '.' == missing, 'R' == replacing)
>
> Signed-off-by: Lidong Zhong <lzhong@suse.com>
> ---
>  super1.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/super1.c b/super1.c
> index 2fcb814..811923f 100644
> --- a/super1.c
> +++ b/super1.c
> @@ -1267,8 +1267,13 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>  				break;
>  		sb->dev_number = __cpu_to_le32(i);
>  		info->disk.number = i;
> -		if (max >= __le32_to_cpu(sb->max_dev))
> -			sb->max_dev = __cpu_to_le32(max+1);
> +		if (i >= max) {
> +			while (max <= i) {
> +				sb->dev_roles[max] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
> +				max += 1;
> +			}
> +			sb->max_dev = __cpu_to_le32(max);
> +		}

This part of the patch is OK....

>  
>  		random_uuid(sb->device_uuid);
>  
> @@ -1296,6 +1301,10 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>  		sb->raid_disks = __cpu_to_le32(info->array.raid_disks);
>  		sb->dev_roles[info->disk.number] =
>  			__cpu_to_le16(info->disk.raid_disk);
> +		if (sb->raid_disks+1 >= __le32_to_cpu(sb->max_dev)) {

sb->raid_disks is an le32 number, not a cpu number.  So adding 1 to
it is clearly wrong.

Why do you think you need a change here at all?

NeilBrown


> +			sb->dev_roles[sb->raid_disks] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
> +			sb->max_dev = __cpu_to_le32(sb->raid_disks+1);
> +		}
>  	} else if (strcmp(update, "resync") == 0) {
>  		/* make sure resync happens */
>  		sb->resync_offset = 0ULL;
> -- 
> 2.12.0

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

* Re: [PATCH v3] super1: fix sb->max_dev when adding a new disk in linear array
  2017-05-21 23:31 ` NeilBrown
@ 2017-05-22  3:28   ` Lidong Zhong
  2017-05-22  4:35     ` NeilBrown
  0 siblings, 1 reply; 4+ messages in thread
From: Lidong Zhong @ 2017-05-22  3:28 UTC (permalink / raw)
  To: NeilBrown, linux-raid; +Cc: colyli, Jes.Sorensen



On 05/22/2017 07:31 AM, NeilBrown wrote:
> On Fri, May 19 2017, Lidong Zhong wrote:
>
>> The value of sb->max_dev will always be increased by 1 when adding
>> a new disk in linear array. It causes an inconsistence between each
>> disk in the array and the "Array State" value of "mdadm --examine DISK"
>> is wrong. For example, when adding the first new disk into linear array
>> it will be:
>>
>> Array State : RAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>> ('A' == active, '.' == missing, 'R' == replacing)
>>
>> Adding the second disk into linear array it will be
>>
>> Array State : .AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>> ('A' == active, '.' == missing, 'R' == replacing)
>>
>> Signed-off-by: Lidong Zhong <lzhong@suse.com>
>> ---
>>  super1.c | 13 +++++++++++--
>>  1 file changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/super1.c b/super1.c
>> index 2fcb814..811923f 100644
>> --- a/super1.c
>> +++ b/super1.c
>> @@ -1267,8 +1267,13 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>>  				break;
>>  		sb->dev_number = __cpu_to_le32(i);
>>  		info->disk.number = i;
>> -		if (max >= __le32_to_cpu(sb->max_dev))
>> -			sb->max_dev = __cpu_to_le32(max+1);
>> +		if (i >= max) {
>> +			while (max <= i) {
>> +				sb->dev_roles[max] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
>> +				max += 1;
>> +			}
>> +			sb->max_dev = __cpu_to_le32(max);
>> +		}
>
> This part of the patch is OK....
>
>>
>>  		random_uuid(sb->device_uuid);
>>
>> @@ -1296,6 +1301,10 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>>  		sb->raid_disks = __cpu_to_le32(info->array.raid_disks);
>>  		sb->dev_roles[info->disk.number] =
>>  			__cpu_to_le16(info->disk.raid_disk);
>> +		if (sb->raid_disks+1 >= __le32_to_cpu(sb->max_dev)) {
>
> sb->raid_disks is an le32 number, not a cpu number.  So adding 1 to
> it is clearly wrong.
>

Really sorry for the careless...I mean info->array.raid_disks here.

> Why do you think you need a change here at all?
>

The first part of this patch is dealing with the newly added disk
when the disk number is greater than sb->max_dev.
While updating the superblock on the original disks of the linear
array, shouldn't I also check if the disk numbers is greater
than sb->max_dev?


  254         info.array.raid_disks = nd+1;
  255         info.array.nr_disks = nd+1;
  256         info.array.active_disks = nd+1;
  257         info.array.working_disks = nd+1;
  258
  259         st->ss->update_super(st, &info, "linear-grow-update", dv,
  260                      0, 0, NULL);
  261
  262         if (st->ss->store_super(st, fd2)) {
  263             pr_err("Cannot store new superblock on %s\n", dv);
  264             close(fd2);
  265             return 1;
  266         }


Thanks,
Lidong
> NeilBrown
>
>
>> +			sb->dev_roles[sb->raid_disks] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
>> +			sb->max_dev = __cpu_to_le32(sb->raid_disks+1);
>> +		}
>>  	} else if (strcmp(update, "resync") == 0) {
>>  		/* make sure resync happens */
>>  		sb->resync_offset = 0ULL;
>> --
>> 2.12.0

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

* Re: [PATCH v3] super1: fix sb->max_dev when adding a new disk in linear array
  2017-05-22  3:28   ` Lidong Zhong
@ 2017-05-22  4:35     ` NeilBrown
  0 siblings, 0 replies; 4+ messages in thread
From: NeilBrown @ 2017-05-22  4:35 UTC (permalink / raw)
  To: Lidong Zhong, linux-raid; +Cc: colyli, Jes.Sorensen

[-- Attachment #1: Type: text/plain, Size: 3800 bytes --]

On Mon, May 22 2017, Lidong Zhong wrote:

> On 05/22/2017 07:31 AM, NeilBrown wrote:
>> On Fri, May 19 2017, Lidong Zhong wrote:
>>
>>> The value of sb->max_dev will always be increased by 1 when adding
>>> a new disk in linear array. It causes an inconsistence between each
>>> disk in the array and the "Array State" value of "mdadm --examine DISK"
>>> is wrong. For example, when adding the first new disk into linear array
>>> it will be:
>>>
>>> Array State : RAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>>> ('A' == active, '.' == missing, 'R' == replacing)
>>>
>>> Adding the second disk into linear array it will be
>>>
>>> Array State : .AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>>> ('A' == active, '.' == missing, 'R' == replacing)
>>>
>>> Signed-off-by: Lidong Zhong <lzhong@suse.com>
>>> ---
>>>  super1.c | 13 +++++++++++--
>>>  1 file changed, 11 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/super1.c b/super1.c
>>> index 2fcb814..811923f 100644
>>> --- a/super1.c
>>> +++ b/super1.c
>>> @@ -1267,8 +1267,13 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>>>  				break;
>>>  		sb->dev_number = __cpu_to_le32(i);
>>>  		info->disk.number = i;
>>> -		if (max >= __le32_to_cpu(sb->max_dev))
>>> -			sb->max_dev = __cpu_to_le32(max+1);
>>> +		if (i >= max) {
>>> +			while (max <= i) {
>>> +				sb->dev_roles[max] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
>>> +				max += 1;
>>> +			}
>>> +			sb->max_dev = __cpu_to_le32(max);
>>> +		}
>>
>> This part of the patch is OK....
>>
>>>
>>>  		random_uuid(sb->device_uuid);
>>>
>>> @@ -1296,6 +1301,10 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>>>  		sb->raid_disks = __cpu_to_le32(info->array.raid_disks);
>>>  		sb->dev_roles[info->disk.number] =
>>>  			__cpu_to_le16(info->disk.raid_disk);
>>> +		if (sb->raid_disks+1 >= __le32_to_cpu(sb->max_dev)) {
>>
>> sb->raid_disks is an le32 number, not a cpu number.  So adding 1 to
>> it is clearly wrong.
>>
>
> Really sorry for the careless...I mean info->array.raid_disks here.
>
>> Why do you think you need a change here at all?
>>
>
> The first part of this patch is dealing with the newly added disk
> when the disk number is greater than sb->max_dev.
> While updating the superblock on the original disks of the linear
> array, shouldn't I also check if the disk numbers is greater
> than sb->max_dev?

OK, I can see that you might need to update max_dev to make sure that it
is larger than the new disk.number (or equal to the new raid_disks).
I don't see why you need to make it bigger than raid_disks, or why you
need to change ->dev_roles[] any more than it is already being changed.

i.e. the *only* bug here is with the way max_dev is being updated.
Just change that (in two places).

I don't think the "while (max <= i)" is really needed.  I know I wrote
it, and it isn't wrong.  But it will always do nothing (except increment
'max' once).  So there really isn't any point.

NeilBrown



>
>
>   254         info.array.raid_disks = nd+1;
>   255         info.array.nr_disks = nd+1;
>   256         info.array.active_disks = nd+1;
>   257         info.array.working_disks = nd+1;
>   258
>   259         st->ss->update_super(st, &info, "linear-grow-update", dv,
>   260                      0, 0, NULL);
>   261
>   262         if (st->ss->store_super(st, fd2)) {
>   263             pr_err("Cannot store new superblock on %s\n", dv);
>   264             close(fd2);
>   265             return 1;
>   266         }
>


>>
>>
>>> +			sb->dev_roles[sb->raid_disks] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
>>> +			sb->max_dev = __cpu_to_le32(sb->raid_disks+1);
>>> +		}
>>>  	} else if (strcmp(update, "resync") == 0) {
>>>  		/* make sure resync happens */
>>>  		sb->resync_offset = 0ULL;
>>> --
>>> 2.12.0

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

end of thread, other threads:[~2017-05-22  4:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-19  6:06 [PATCH v3] super1: fix sb->max_dev when adding a new disk in linear array Lidong Zhong
2017-05-21 23:31 ` NeilBrown
2017-05-22  3:28   ` Lidong Zhong
2017-05-22  4:35     ` NeilBrown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.