On Mon, May 22 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@xxxxxxxx> > --- > super1.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/super1.c b/super1.c > index 2fcb814..03cea72 100644 > --- a/super1.c > +++ b/super1.c > @@ -1267,8 +1267,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 >= max) { > + sb->dev_roles[max] = __cpu_to_le16(MD_DISK_ROLE_SPARE); Why do you assign to dev_roles[max]? max must equal i here, and a few lines later: sb->dev_roles[i] = __cpu_to_le16(info->disk.raid_disk); your assignment is over-written. So it is pointless. If i was greater than max (which should be impossible), you assignment here would corrupt the dev_roles table. Please drop this assignment. > sb->max_dev = __cpu_to_le32(max+1); > + } > > random_uuid(sb->device_uuid); > > @@ -1293,9 +1295,14 @@ static int update_super1(struct supertype *st, struct mdinfo *info, > } > } > } else if (strcmp(update, "linear-grow-update") == 0) { > + unsigned int max = __le32_to_cpu(sb->max_dev); > sb->raid_disks = __cpu_to_le32(info->array.raid_disks); > sb->dev_roles[info->disk.number] = > __cpu_to_le16(info->disk.raid_disk); > + if (info->array.raid_disks >= max) { if raid_disks == max there is no need to change anything. It is only when raid_disks > max that you need to increase max. > + sb->dev_roles[max] = __cpu_to_le16(MD_DISK_ROLE_SPARE); When you increase max, you do need to assign MD_DISK_ROLE_SPARE to the new element, but you need to do that *before* disk.raid_disk is assigned, in case info->disk.number == max (as it could be for the recently added device). NeilBrown > + sb->max_dev = __cpu_to_le32(max+1); > + } > } else if (strcmp(update, "resync") == 0) { > /* make sure resync happens */ > sb->resync_offset = 0ULL; > -- > 2.12.0
Attachment:
signature.asc
Description: PGP signature