提交 a778b73f 编写于 作者: N NeilBrown 提交者: Linus Torvalds

md: fix bug with linear hot-add and elsewhere

Adding a drive to a linear array seems to have stopped working, due to changes
elsewhere in md, and insufficient ongoing testing...

So the patch to make linear hot-add work in the first place introduced a
subtle bug elsewhere that interracts poorly with older version of mdadm.

This fixes it all up.
Signed-off-by: NNeil Brown <neilb@suse.de>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 ab6085c7
...@@ -139,8 +139,6 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) ...@@ -139,8 +139,6 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
if (!conf) if (!conf)
return NULL; return NULL;
mddev->private = conf;
cnt = 0; cnt = 0;
conf->array_size = 0; conf->array_size = 0;
...@@ -232,7 +230,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) ...@@ -232,7 +230,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
* First calculate the device offsets. * First calculate the device offsets.
*/ */
conf->disks[0].offset = 0; conf->disks[0].offset = 0;
for (i=1; i<mddev->raid_disks; i++) for (i = 1; i < raid_disks; i++)
conf->disks[i].offset = conf->disks[i].offset =
conf->disks[i-1].offset + conf->disks[i-1].offset +
conf->disks[i-1].size; conf->disks[i-1].size;
...@@ -244,7 +242,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks) ...@@ -244,7 +242,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
curr_offset < conf->array_size; curr_offset < conf->array_size;
curr_offset += conf->hash_spacing) { curr_offset += conf->hash_spacing) {
while (i < mddev->raid_disks-1 && while (i < raid_disks-1 &&
curr_offset >= conf->disks[i+1].offset) curr_offset >= conf->disks[i+1].offset)
i++; i++;
...@@ -299,9 +297,11 @@ static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev) ...@@ -299,9 +297,11 @@ static int linear_add(mddev_t *mddev, mdk_rdev_t *rdev)
*/ */
linear_conf_t *newconf; linear_conf_t *newconf;
if (rdev->raid_disk != mddev->raid_disks) if (rdev->saved_raid_disk != mddev->raid_disks)
return -EINVAL; return -EINVAL;
rdev->raid_disk = rdev->saved_raid_disk;
newconf = linear_conf(mddev,mddev->raid_disks+1); newconf = linear_conf(mddev,mddev->raid_disks+1);
if (!newconf) if (!newconf)
......
...@@ -1299,6 +1299,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev) ...@@ -1299,6 +1299,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
if (rdev2->desc_nr+1 > max_dev) if (rdev2->desc_nr+1 > max_dev)
max_dev = rdev2->desc_nr+1; max_dev = rdev2->desc_nr+1;
if (max_dev > le32_to_cpu(sb->max_dev))
sb->max_dev = cpu_to_le32(max_dev); sb->max_dev = cpu_to_le32(max_dev);
for (i=0; i<max_dev;i++) for (i=0; i<max_dev;i++)
sb->dev_roles[i] = cpu_to_le16(0xfffe); sb->dev_roles[i] = cpu_to_le16(0xfffe);
...@@ -1365,10 +1366,14 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) ...@@ -1365,10 +1366,14 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
} }
/* make sure rdev->size exceeds mddev->size */ /* make sure rdev->size exceeds mddev->size */
if (rdev->size && (mddev->size == 0 || rdev->size < mddev->size)) { if (rdev->size && (mddev->size == 0 || rdev->size < mddev->size)) {
if (mddev->pers) if (mddev->pers) {
/* Cannot change size, so fail */ /* Cannot change size, so fail
* If mddev->level <= 0, then we don't care
* about aligning sizes (e.g. linear)
*/
if (mddev->level > 0)
return -ENOSPC; return -ENOSPC;
else } else
mddev->size = rdev->size; mddev->size = rdev->size;
} }
...@@ -2142,6 +2147,9 @@ static void analyze_sbs(mddev_t * mddev) ...@@ -2142,6 +2147,9 @@ static void analyze_sbs(mddev_t * mddev)
rdev->desc_nr = i++; rdev->desc_nr = i++;
rdev->raid_disk = rdev->desc_nr; rdev->raid_disk = rdev->desc_nr;
set_bit(In_sync, &rdev->flags); set_bit(In_sync, &rdev->flags);
} else if (rdev->raid_disk >= mddev->raid_disks) {
rdev->raid_disk = -1;
clear_bit(In_sync, &rdev->flags);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册