Browse Source

md: don't allow arrays to contain devices with bad blocks.

As no personality understand bad block lists yet, we must
reject any device that is known to contain bad blocks.
As the personalities get taught, these tests can be removed.

This only applies to raid1/raid5/raid10.
For linear/raid0/multipath/faulty the whole concept of bad blocks
doesn't mean anything so there is no point adding the checks.

Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Namhyung Kim <namhyung@gmail.com>
NeilBrown 14 years ago
parent
commit
34b343cff4
3 changed files with 22 additions and 0 deletions
  1. 7 0
      drivers/md/raid1.c
  2. 8 0
      drivers/md/raid10.c
  3. 7 0
      drivers/md/raid5.c

+ 7 - 0
drivers/md/raid1.c

@@ -1055,6 +1055,9 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 	if (mddev->recovery_disabled == conf->recovery_disabled)
 	if (mddev->recovery_disabled == conf->recovery_disabled)
 		return -EBUSY;
 		return -EBUSY;
 
 
+	if (rdev->badblocks.count)
+		return -EINVAL;
+
 	if (rdev->raid_disk >= 0)
 	if (rdev->raid_disk >= 0)
 		first = last = rdev->raid_disk;
 		first = last = rdev->raid_disk;
 
 
@@ -1994,6 +1997,10 @@ static int run(mddev_t *mddev)
 			blk_queue_segment_boundary(mddev->queue,
 			blk_queue_segment_boundary(mddev->queue,
 						   PAGE_CACHE_SIZE - 1);
 						   PAGE_CACHE_SIZE - 1);
 		}
 		}
+		if (rdev->badblocks.count) {
+			printk(KERN_ERR "md/raid1: Cannot handle bad blocks yet\n");
+			return -EINVAL;
+		}
 	}
 	}
 
 
 	mddev->degraded = 0;
 	mddev->degraded = 0;

+ 8 - 0
drivers/md/raid10.c

@@ -1101,6 +1101,9 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 	int first = 0;
 	int first = 0;
 	int last = conf->raid_disks - 1;
 	int last = conf->raid_disks - 1;
 
 
+	if (rdev->badblocks.count)
+		return -EINVAL;
+
 	if (mddev->recovery_cp < MaxSector)
 	if (mddev->recovery_cp < MaxSector)
 		/* only hot-add to in-sync arrays, as recovery is
 		/* only hot-add to in-sync arrays, as recovery is
 		 * very different from resync
 		 * very different from resync
@@ -2263,6 +2266,11 @@ static int run(mddev_t *mddev)
 				 (conf->raid_disks / conf->near_copies));
 				 (conf->raid_disks / conf->near_copies));
 
 
 	list_for_each_entry(rdev, &mddev->disks, same_set) {
 	list_for_each_entry(rdev, &mddev->disks, same_set) {
+
+		if (rdev->badblocks.count) {
+			printk(KERN_ERR "md/raid10: cannot handle bad blocks yet\n");
+			goto out_free_conf;
+		}
 		disk_idx = rdev->raid_disk;
 		disk_idx = rdev->raid_disk;
 		if (disk_idx >= conf->raid_disks
 		if (disk_idx >= conf->raid_disks
 		    || disk_idx < 0)
 		    || disk_idx < 0)

+ 7 - 0
drivers/md/raid5.c

@@ -4667,6 +4667,10 @@ static int run(mddev_t *mddev)
 	 * 0 for a fully functional array, 1 or 2 for a degraded array.
 	 * 0 for a fully functional array, 1 or 2 for a degraded array.
 	 */
 	 */
 	list_for_each_entry(rdev, &mddev->disks, same_set) {
 	list_for_each_entry(rdev, &mddev->disks, same_set) {
+		if (rdev->badblocks.count) {
+			printk(KERN_ERR "md/raid5: cannot handle bad blocks yet\n");
+			goto abort;
+		}
 		if (rdev->raid_disk < 0)
 		if (rdev->raid_disk < 0)
 			continue;
 			continue;
 		if (test_bit(In_sync, &rdev->flags)) {
 		if (test_bit(In_sync, &rdev->flags)) {
@@ -4975,6 +4979,9 @@ static int raid5_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
 	int first = 0;
 	int first = 0;
 	int last = conf->raid_disks - 1;
 	int last = conf->raid_disks - 1;
 
 
+	if (rdev->badblocks.count)
+		return -EINVAL;
+
 	if (has_failed(conf))
 	if (has_failed(conf))
 		/* no point adding a device */
 		/* no point adding a device */
 		return -EINVAL;
 		return -EINVAL;