aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/md.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2009-02-06 02:02:46 -0500
committerNeilBrown <neilb@suse.de>2009-02-06 02:02:46 -0500
commitde01dfadf25bf83cfe3d85c163005c4320532658 (patch)
treedc1cca5a6aa10ecc0fea2fb9f13534685ba8ff61 /drivers/md/md.c
parent852c8bf484a0e17ee27f413ef26e87f522af5607 (diff)
md: Ensure an md array never has too many devices.
Each different metadata format supported by md supports a different maximum number of devices. We really should be enforcing this maximum in the kernel, but we aren't quite doing that properly. We currently only enforce it at the 'hot_add' point, which is an older interface which is not used by current userspace. We need to also enforce it at 'add_new_disk' time for active arrays and at 'do_md_run' time when starting a new array. So move the test from 'hot_add' into 'bind_rdev_to_array' which is called from both 'hot_add' and 'add_new_disk, and add a new test in 'analyse_sbs' which is called from 'do_md_run'. This bug (or missing feature) has been around "forever" and so the patch is suitable for any -stable that is currently maintained. Cc: stable@kernel.org Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r--drivers/md/md.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 41e2509bf896..4495104f6c9f 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1481,6 +1481,11 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
1481 if (find_rdev_nr(mddev, rdev->desc_nr)) 1481 if (find_rdev_nr(mddev, rdev->desc_nr))
1482 return -EBUSY; 1482 return -EBUSY;
1483 } 1483 }
1484 if (mddev->max_disks && rdev->desc_nr >= mddev->max_disks) {
1485 printk(KERN_WARNING "md: %s: array is limited to %d devices\n",
1486 mdname(mddev), mddev->max_disks);
1487 return -EBUSY;
1488 }
1484 bdevname(rdev->bdev,b); 1489 bdevname(rdev->bdev,b);
1485 while ( (s=strchr(b, '/')) != NULL) 1490 while ( (s=strchr(b, '/')) != NULL)
1486 *s = '!'; 1491 *s = '!';
@@ -2441,6 +2446,15 @@ static void analyze_sbs(mddev_t * mddev)
2441 2446
2442 i = 0; 2447 i = 0;
2443 rdev_for_each(rdev, tmp, mddev) { 2448 rdev_for_each(rdev, tmp, mddev) {
2449 if (rdev->desc_nr >= mddev->max_disks ||
2450 i > mddev->max_disks) {
2451 printk(KERN_WARNING
2452 "md: %s: %s: only %d devices permitted\n",
2453 mdname(mddev), bdevname(rdev->bdev, b),
2454 mddev->max_disks);
2455 kick_rdev_from_array(rdev);
2456 continue;
2457 }
2444 if (rdev != freshest) 2458 if (rdev != freshest)
2445 if (super_types[mddev->major_version]. 2459 if (super_types[mddev->major_version].
2446 validate_super(mddev, rdev)) { 2460 validate_super(mddev, rdev)) {
@@ -4614,13 +4628,6 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
4614 * noticed in interrupt contexts ... 4628 * noticed in interrupt contexts ...
4615 */ 4629 */
4616 4630
4617 if (rdev->desc_nr == mddev->max_disks) {
4618 printk(KERN_WARNING "%s: can not hot-add to full array!\n",
4619 mdname(mddev));
4620 err = -EBUSY;
4621 goto abort_unbind_export;
4622 }
4623
4624 rdev->raid_disk = -1; 4631 rdev->raid_disk = -1;
4625 4632
4626 md_update_sb(mddev, 1); 4633 md_update_sb(mddev, 1);
@@ -4634,9 +4641,6 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
4634 md_new_event(mddev); 4641 md_new_event(mddev);
4635 return 0; 4642 return 0;
4636 4643
4637abort_unbind_export:
4638 unbind_rdev_from_array(rdev);
4639
4640abort_export: 4644abort_export:
4641 export_rdev(rdev); 4645 export_rdev(rdev);
4642 return err; 4646 return err;