Skip to content

Commit

Permalink
dm thin: fix non power of two discard granularity calc
Browse files Browse the repository at this point in the history
Fix a discard granularity calculation to work for non power of 2 block sizes.

In order for thinp to passdown discard bios to the underlying data
device, the data device must have a discard granularity that is a
factor of the thinp block size.  Originally this check was done by
using bitops since the block_size was known to be a power of two.

Introduced by commit f13945d
("dm thin: support a non power of 2 discard_granularity").

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
  • Loading branch information
Joe Thornber authored and Alasdair G Kergon committed Mar 20, 2013
1 parent f046f89 commit 58051b9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/md/dm-thin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,11 @@ static bool data_dev_supports_discard(struct pool_c *pt)
return q && blk_queue_discard(q);
}

static bool is_factor(sector_t block_size, uint32_t n)
{
return !sector_div(block_size, n);
}

/*
* If discard_passdown was enabled verify that the data device
* supports discards. Disable discard_passdown if not.
Expand All @@ -1602,7 +1607,7 @@ static void disable_passdown_if_not_supported(struct pool_c *pt)
else if (data_limits->discard_granularity > block_size)
reason = "discard granularity larger than a block";

else if (block_size & (data_limits->discard_granularity - 1))
else if (!is_factor(block_size, data_limits->discard_granularity))
reason = "discard granularity not a factor of block size";

if (reason) {
Expand Down

0 comments on commit 58051b9

Please sign in to comment.