[PATCHv2]brd: set max_discard_sectors properly

From: Jinpu Wang
Date: Fri Apr 15 2016 - 10:24:47 EST


Hi,

blkdiscard fails on brd with IO error on 4.4.5, and latest mainline
looks the same.
nbd and zram has same defect, I can send fix later, if you are Ok with this fix.
From a5db7d1acdb54b7f188eb916f711733e34da5b5f Mon Sep 17 00:00:00 2001
From: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxxx>
Date: Fri, 15 Apr 2016 16:05:16 +0200
Subject: [PATCH] brd: set max_discard_sectors properly

blkdiscard -v /dev/ram0 fails with IO errors, the reason seems to be,
it set max_discard_sectors to UINT_MAX, which seems to wrong, need to
convert to sectors.

After this change blkdiscard works.

Signed-off-by: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxxx>
---
drivers/block/brd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index a5880f4..a5e3c0f 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -503,7 +503,7 @@ static struct brd_device *brd_alloc(int i)
blk_queue_physical_block_size(brd->brd_queue, PAGE_SIZE);

brd->brd_queue->limits.discard_granularity = PAGE_SIZE;
- blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX);
+ blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX >> 9);
brd->brd_queue->limits.discard_zeroes_data = 1;
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, brd->brd_queue);

--
1.9.1