From: Mikulas Patocka <mpatocka@redhat.com>

The kernel currently assumes that limits->discard_granularity is a power
of two so the thin target can set this limit only if it uses a power of
two block size.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

---
drivers/md/dm-thin.c |    3 ++-
 drivers/md/dm-thin.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux/drivers/md/dm-thin.c
===================================================================
--- linux.orig/drivers/md/dm-thin.c
+++ linux/drivers/md/dm-thin.c
@@ -2498,7 +2498,8 @@ static void set_discard_limits(struct po
 	 * This is just a hint, and not enforced.  We have to cope with
 	 * bios that overlap 2 blocks.
 	 */
-	limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT;
+	if (!(pool->sectors_per_block & (pool->sectors_per_block - 1)))
+		limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT;
 	limits->discard_zeroes_data = pool->pf.zero_new_blocks;
 }
 
