summaryrefslogtreecommitdiffstats
path: root/drivers/md/md.c
diff options
context:
space:
mode:
authorraz ben yehuda <raziebe@gmail.com>2009-06-16 17:01:42 +1000
committerNeilBrown <neilb@suse.de>2009-06-16 17:01:42 +1000
commit2ac06c3332898103210b478c5a17c20e28929287 (patch)
tree6f34315bbdcc8a8300ab2ab5edcd4cb96150e583 /drivers/md/md.c
parent740da44918680a0c72411ae4ccdd1861069afcc4 (diff)
md: prepare for non-power-of-two chunk sizes
Remove chunk size check from md as this is now performed in the run function in each personality. Replace chunk size power 2 code calculations by a regular division. Signed-off-by: raziebe@gmail.com Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r--drivers/md/md.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 20f6ac33834..a02bde70874 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -444,8 +444,11 @@ static sector_t calc_num_sectors(mdk_rdev_t *rdev, unsigned chunk_size)
{
sector_t num_sectors = rdev->sb_start;
- if (chunk_size)
- num_sectors &= ~((sector_t)chunk_size/512 - 1);
+ if (chunk_size) {
+ unsigned chunk_sects = chunk_size>>9;
+ sector_div(num_sectors, chunk_sects);
+ num_sectors *= chunk_sects;
+ }
return num_sectors;
}
@@ -1248,8 +1251,12 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
if (rdev->sectors < le64_to_cpu(sb->data_size))
return -EINVAL;
rdev->sectors = le64_to_cpu(sb->data_size);
- if (le32_to_cpu(sb->chunksize))
- rdev->sectors &= ~((sector_t)le32_to_cpu(sb->chunksize) - 1);
+ if (le32_to_cpu(sb->chunksize)) {
+ int chunk_sects = le32_to_cpu(sb->chunksize);
+ sector_t chunks = rdev->sectors;
+ sector_div(chunks, chunk_sects);
+ rdev->sectors = chunks * chunk_sects;
+ }
if (le64_to_cpu(sb->size) > rdev->sectors)
return -EINVAL;
@@ -3528,7 +3535,8 @@ min_sync_store(mddev_t *mddev, const char *buf, size_t len)
/* Must be a multiple of chunk_size */
if (mddev->chunk_size) {
- if (min & (sector_t)((mddev->chunk_size>>9)-1))
+ sector_t temp = min;
+ if (sector_div(temp, (mddev->chunk_size>>9)))
return -EINVAL;
}
mddev->resync_min = min;
@@ -3565,7 +3573,8 @@ max_sync_store(mddev_t *mddev, const char *buf, size_t len)
/* Must be a multiple of chunk_size */
if (mddev->chunk_size) {
- if (max & (sector_t)((mddev->chunk_size>>9)-1))
+ sector_t temp = max;
+ if (sector_div(temp, (mddev->chunk_size>>9)))
return -EINVAL;
}
mddev->resync_max = max;
@@ -4006,14 +4015,6 @@ static int do_md_run(mddev_t * mddev)
chunk_size, MAX_CHUNK_SIZE);
return -EINVAL;
}
- /*
- * chunk-size has to be a power of 2
- */
- if ( (1 << ffz(~chunk_size)) != chunk_size) {
- printk(KERN_ERR "chunk_size of %d not valid\n", chunk_size);
- return -EINVAL;
- }
-
/* devices must have minimum size of one chunk */
list_for_each_entry(rdev, &mddev->disks, same_set) {
if (test_bit(Faulty, &rdev->flags))