* [PATCH] DM RAID: Ensure the bitmap region_size is a power of 2
@ 2012-12-11 21:37 Jonathan Brassow
2012-12-11 21:49 ` Alasdair G Kergon
2012-12-12 14:53 ` Jonathan Brassow
0 siblings, 2 replies; 4+ messages in thread
From: Jonathan Brassow @ 2012-12-11 21:37 UTC (permalink / raw)
To: linux-raid; +Cc: neilb, agk, jbrassow
DM RAID: Ensure the bitmap region_size is a power of 2
If the user does not supply a region_size, a reasonable size is computed
automatically. However, region_size needs to be a power of 2 and the
code was not properly ensuring that.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Index: linux-upstream/drivers/md/dm-raid.c
===================================================================
--- linux-upstream.orig/drivers/md/dm-raid.c
+++ linux-upstream/drivers/md/dm-raid.c
@@ -288,6 +288,7 @@ static int dev_parms(struct raid_set *rs
*/
static int validate_region_size(struct raid_set *rs, unsigned long region_size)
{
+ int i;
unsigned long min_region_size = rs->ti->len / (1 << 21);
if (!region_size) {
@@ -295,9 +296,12 @@ static int validate_region_size(struct r
* Choose a reasonable default. All figures in sectors.
*/
if (min_region_size > (1 << 13)) {
+ /* region_size must be a power of 2 */
+ for (i = 13; min_region_size > (1 << i); i++);
+
+ region_size = (1 << i);
DMINFO("Choosing default region size of %lu sectors",
region_size);
- region_size = min_region_size;
} else {
DMINFO("Choosing default region size of 4MiB");
region_size = 1 << 13; /* sectors */
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] DM RAID: Ensure the bitmap region_size is a power of 2
2012-12-11 21:37 [PATCH] DM RAID: Ensure the bitmap region_size is a power of 2 Jonathan Brassow
@ 2012-12-11 21:49 ` Alasdair G Kergon
2012-12-12 14:53 ` Jonathan Brassow
1 sibling, 0 replies; 4+ messages in thread
From: Alasdair G Kergon @ 2012-12-11 21:49 UTC (permalink / raw)
To: Jonathan Brassow; +Cc: linux-raid, neilb, agk
On Tue, Dec 11, 2012 at 03:37:05PM -0600, Jon Brassow wrote:
> if (min_region_size > (1 << 13)) {
> + /* region_size must be a power of 2 */
> + for (i = 13; min_region_size > (1 << i); i++);
> +
> + region_size = (1 << i);
Can the loop be replaced with a direct bit calculation, perhaps?
Alasdair
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] DM RAID: Ensure the bitmap region_size is a power of 2
2012-12-11 21:37 [PATCH] DM RAID: Ensure the bitmap region_size is a power of 2 Jonathan Brassow
2012-12-11 21:49 ` Alasdair G Kergon
@ 2012-12-12 14:53 ` Jonathan Brassow
2012-12-12 16:10 ` Alasdair G Kergon
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Brassow @ 2012-12-12 14:53 UTC (permalink / raw)
To: linux-raid; +Cc: neilb, agk, jbrassow
This is probably a better way to do it...
brassow
DM RAID: Ensure the bitmap region_size is a power of 2
If the user does not supply a region_size, a reasonable size is computed
automatically. However, region_size needs to be a power of 2 and the
code was not properly ensuring that.
Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Index: linux-upstream/drivers/md/dm-raid.c
===================================================================
--- linux-upstream.orig/drivers/md/dm-raid.c
+++ linux-upstream/drivers/md/dm-raid.c
@@ -295,9 +295,11 @@ static int validate_region_size(struct r
* Choose a reasonable default. All figures in sectors.
*/
if (min_region_size > (1 << 13)) {
+ /* If not a power of 2, make it the next power of 2 */
+ if (min_region_size & (min_region_size - 1))
+ region_size = 1 << fls(region_size);
DMINFO("Choosing default region size of %lu sectors",
region_size);
- region_size = min_region_size;
} else {
DMINFO("Choosing default region size of 4MiB");
region_size = 1 << 13; /* sectors */
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] DM RAID: Ensure the bitmap region_size is a power of 2
2012-12-12 14:53 ` Jonathan Brassow
@ 2012-12-12 16:10 ` Alasdair G Kergon
0 siblings, 0 replies; 4+ messages in thread
From: Alasdair G Kergon @ 2012-12-12 16:10 UTC (permalink / raw)
To: Jonathan Brassow; +Cc: linux-raid, neilb, agk
On Wed, Dec 12, 2012 at 08:53:32AM -0600, Jon Brassow wrote:
> This is probably a better way to do it...
Indeed. I'll pick this one up.
> DM RAID: Ensure the bitmap region_size is a power of 2
>
> If the user does not supply a region_size, a reasonable size is computed
> automatically. However, region_size needs to be a power of 2 and the
> code was not properly ensuring that.
And this is just a cleanup patch: to provide a controlled error message
here, rather than triggering a controlled error inside the md code
later.
Alasdair
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-12-12 16:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-11 21:37 [PATCH] DM RAID: Ensure the bitmap region_size is a power of 2 Jonathan Brassow
2012-12-11 21:49 ` Alasdair G Kergon
2012-12-12 14:53 ` Jonathan Brassow
2012-12-12 16:10 ` Alasdair G Kergon
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).