diff options
author | NeilBrown <neilb@suse.de> | 2013-02-21 14:33:17 +1100 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2013-03-20 15:03:18 +0000 |
commit | 84453f1a9d27a3a9be88269cc14ee9099856f268 (patch) | |
tree | 0cd73487f3fd09a4c994bcaf18c20aad22c3abf8 /drivers | |
parent | b923f0d70914a257e4545ede4155f9889acc653b (diff) |
md: fix two bugs when attempting to resize RAID0 array.
commit a64685399181780998281fe07309a94b25dd24c3 upstream.
You cannot resize a RAID0 array (in terms of making the devices
bigger), but the code doesn't entirely stop you.
So:
disable setting of the available size on each device for
RAID0 and Linear devices. This must not change as doing so
can change the effective layout of data.
Make sure that the size that raid0_size() reports is accurate,
but rounding devices sizes to chunk sizes. As the device sizes
cannot change now, this isn't so important, but it is best to be
safe.
Without this change:
mdadm --grow /dev/md0 -z max
mdadm --grow /dev/md0 -Z max
then read to the end of the array
can cause a BUG in a RAID0 array.
These bugs have been present ever since it became possible
to resize any device, which is a long time. So the fix is
suitable for any -stable kerenl.
Signed-off-by: NeilBrown <neilb@suse.de>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/md/md.c | 3 | ||||
-rw-r--r-- | drivers/md/raid0.c | 3 |
2 files changed, 5 insertions, 1 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index 5cbc496c6de..1702133a91a 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -2842,6 +2842,9 @@ rdev_size_store(struct md_rdev *rdev, const char *buf, size_t len) } else if (!sectors) sectors = (i_size_read(rdev->bdev->bd_inode) >> 9) - rdev->data_offset; + if (!my_mddev->pers->resize) + /* Cannot change size for RAID0 or Linear etc */ + return -EINVAL; } if (sectors < my_mddev->dev_sectors) return -EINVAL; /* component must fit device */ diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c index 7294bd115e3..0c7bff97fdc 100644 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c @@ -330,7 +330,8 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disks "%s does not support generic reshape\n", __func__); list_for_each_entry(rdev, &mddev->disks, same_set) - array_sectors += rdev->sectors; + array_sectors += (rdev->sectors & + ~(sector_t)(mddev->chunk_sectors-1)); return array_sectors; } |