From: NeilBrown <neilb@suse.com>
To: Lidong Zhong <lzhong@suse.com>, linux-raid@vger.kernel.org
Cc: colyli@suse.com, Jes.Sorensen@gmail.com
Subject: Re: [PATCH] super1: fix sb->max_dev when adding a new disk in linear array
Date: Fri, 19 May 2017 15:37:15 +1000 [thread overview]
Message-ID: <87bmqpl850.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <4b01d20c-be52-eaa1-6809-909fb375b274@suse.com>
[-- Attachment #1: Type: text/plain, Size: 4018 bytes --]
On Fri, May 19 2017, Lidong Zhong wrote:
> On 05/19/2017 12:36 PM, NeilBrown wrote:
>> On Tue, May 16 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 | 8 +++++++-
>>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/super1.c b/super1.c
>>> index 87a74cb..3d49bee 100644
>>> --- a/super1.c
>>> +++ b/super1.c
>>> @@ -1184,8 +1184,10 @@ 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))
>>> + if (i >= __le32_to_cpu(sb->max_dev)) {
>>
>> This change is correct - thanks. Though
>> if (i >= max) {
>>
>> might be clearer and simpler.
>>
>>
>>> sb->max_dev = __cpu_to_le32(max+1);
>>> + sb->dev_roles[sb->max_dev] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
>>
>> This change is wrong.
>> At the very least, the dev_roles[] array needs to be indexed by a
>> host-order number, not a little-endian number.
>> But the change is not needed because dev_roles[max_dev] is never used.
>> See role_from_sb().
>> dev_rols[max_dev - 1] does need to be set, but the line
>>
>> sb->dev_roles[i] = __cpu_to_le16(info->disk.raid_disk);
>>
>> almost certainly does that.
> Hi Neil,
>
> The reason I set all the dev_roles[0~max_dev-1] is because
> the following code
>
> 552 printf(" Array State : ");
> 553 for (d = 0; d < __le32_to_cpu(sb->raid_disks) + delta_extra;
> d++) {
> 554 int cnt = 0;
> 555 unsigned int i;
> 556 for (i = 0; i < __le32_to_cpu(sb->max_dev); i++) {
> 557 unsigned int role = __le16_to_cpu(sb->dev_roles[i]);
>
> 558 if (role == d)
>
> 559 cnt++;
>
> 560 }
This code does not access dev_roles[max_dev], only up to
dev_roles[max_dev-1].
You changed dev_roles[max_dev], which will never be accessed.
>
>
>> It might be better to do
>> 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);
>> }
>>
>
>
> Thanks for the advice.
>
>>> + }
>>>
>>> random_uuid(sb->device_uuid);
>>>
>>> @@ -1214,6 +1216,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->max_dev = __cpu_to_le32(sb->raid_disks+1);
>>> + sb->dev_roles[sb->max_dev] = __cpu_to_le16(MD_DISK_ROLE_SPARE);
>>
>> Again, max_dev is little-endian, so cannot be used as an index.
>> And I think you are updating the wrong element in the dev_roles array.
>
> Yes, I didn't realized the valude is conversed to little-endian and the
> index is wrong too. Thank you for pointing this out. I will submit
> another version patch.
I look forward to it,
Thanks,
NeilBrown
>
> Thanks,
> Lidong
>>
>> Thanks,
>> NeilBrown
>>
>>
>>> + }
>>> } 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 --]
next prev parent reply other threads:[~2017-05-19 5:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 4:51 [PATCH] super1: fix sb->max_dev when adding a new disk in linear array Lidong Zhong
2017-05-19 4:36 ` NeilBrown
2017-05-19 5:31 ` Lidong Zhong
2017-05-19 5:37 ` NeilBrown [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-05-12 1:51 Lidong Zhong
2017-05-12 7:53 ` Coly Li
2017-05-15 11:33 ` Lidong Zhong
2017-05-16 4:28 ` Lidong Zhong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bmqpl850.fsf@notabene.neil.brown.name \
--to=neilb@suse.com \
--cc=Jes.Sorensen@gmail.com \
--cc=colyli@suse.com \
--cc=linux-raid@vger.kernel.org \
--cc=lzhong@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).