* Subject: [PATCH 004/009]: md. chunk size check
@ 2009-05-19 16:08 raz ben yehuda
0 siblings, 0 replies; 3+ messages in thread
From: raz ben yehuda @ 2009-05-19 16:08 UTC (permalink / raw)
To: linux raid, neilb; +Cc: ofer, yaron
md fixes
1.move chunk size check from md responsibility to each run function in each raid.
2.replace chunk size power 2 code calculations by a regular division.
md.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
Signed-off-by: raziebe@gmail.com
---
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 279007a..3ac8813 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -444,8 +444,12 @@ 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) {
+ sector_t chunk_sects = chunk_size>>9;
+ sector_t x = num_sectors;
+ sector_div(x, chunk_sects);
+ num_sectors = x*chunk_sects;
+ }
return num_sectors;
}
@@ -3518,7 +3522,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;
@@ -3555,7 +3560,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;
@@ -3996,14 +4002,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))
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Subject: [PATCH 004/009]: md. chunk size check
@ 2009-05-19 16:09 raz ben yehuda
2009-05-20 1:43 ` Neil Brown
0 siblings, 1 reply; 3+ messages in thread
From: raz ben yehuda @ 2009-05-19 16:09 UTC (permalink / raw)
To: linux raid, neilb; +Cc: ofer, yaron
md fixes
1.move chunk size check from md responsibility to each run function in each raid.
2.replace chunk size power 2 code calculations by a regular division.
md.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
Signed-off-by: raziebe@gmail.com
---
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 279007a..3ac8813 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -444,8 +444,12 @@ 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) {
+ sector_t chunk_sects = chunk_size>>9;
+ sector_t x = num_sectors;
+ sector_div(x, chunk_sects);
+ num_sectors = x*chunk_sects;
+ }
return num_sectors;
}
@@ -3518,7 +3522,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;
@@ -3555,7 +3560,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;
@@ -3996,14 +4002,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))
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Subject: [PATCH 004/009]: md. chunk size check
2009-05-19 16:09 Subject: [PATCH 004/009]: md. chunk size check raz ben yehuda
@ 2009-05-20 1:43 ` Neil Brown
0 siblings, 0 replies; 3+ messages in thread
From: Neil Brown @ 2009-05-20 1:43 UTC (permalink / raw)
To: raz ben yehuda; +Cc: linux raid, neilb, ofer, yaron
On Tuesday May 19, raziebe@gmail.com wrote:
> md fixes
> 1.move chunk size check from md responsibility to each run function in each raid.
> 2.replace chunk size power 2 code calculations by a regular division.
Thanks.
I reordered this patch so that it comes *after* the patches which add
checks to the other raid levels. That way the code is correct after
every patch.
NeilBrown
>
> md.c | 22 ++++++++++------------
> 1 file changed, 10 insertions(+), 12 deletions(-)
>
> Signed-off-by: raziebe@gmail.com
> ---
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index 279007a..3ac8813 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -444,8 +444,12 @@ 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) {
> + sector_t chunk_sects = chunk_size>>9;
> + sector_t x = num_sectors;
> + sector_div(x, chunk_sects);
> + num_sectors = x*chunk_sects;
> + }
> return num_sectors;
> }
>
> @@ -3518,7 +3522,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;
> @@ -3555,7 +3560,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;
> @@ -3996,14 +4002,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))
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-05-20 1:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-19 16:09 Subject: [PATCH 004/009]: md. chunk size check raz ben yehuda
2009-05-20 1:43 ` Neil Brown
-- strict thread matches above, loose matches on Subject: below --
2009-05-19 16:08 raz ben yehuda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).