linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2]brd: set max_discard_sectors properly
@ 2016-04-15 14:24 Jinpu Wang
  2016-04-16  1:50 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Jinpu Wang @ 2016-04-15 14:24 UTC (permalink / raw)
  To: Jens Axboe, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 170 bytes --]

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.

[-- Attachment #2: 0001-brd-set-max_discard_sectors-properly.patch --]
[-- Type: text/x-patch, Size: 1113 bytes --]

From a5db7d1acdb54b7f188eb916f711733e34da5b5f Mon Sep 17 00:00:00 2001
From: Jack Wang <jinpu.wang@profitbricks.com>
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@profitbricks.com>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCHv2]brd: set max_discard_sectors properly
  2016-04-15 14:24 [PATCHv2]brd: set max_discard_sectors properly Jinpu Wang
@ 2016-04-16  1:50 ` Christoph Hellwig
  2016-04-18  8:34   ` Jinpu Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2016-04-16  1:50 UTC (permalink / raw)
  To: Jinpu Wang; +Cc: Jens Axboe, linux-kernel

> -	blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX);
> +	blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX >> 9);

Shouldn't we fix the issue by capping to UINT_MAX >> 9 inside
blk_queue_max_discard_sectors?  That way we'll prevent against having
issues like this in any other driver as well.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2]brd: set max_discard_sectors properly
  2016-04-16  1:50 ` Christoph Hellwig
@ 2016-04-18  8:34   ` Jinpu Wang
  2016-04-18 13:55     ` Jinpu Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Jinpu Wang @ 2016-04-18  8:34 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, linux-kernel

On Sat, Apr 16, 2016 at 3:50 AM, Christoph Hellwig <hch@infradead.org> wrote:
>> -     blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX);
>> +     blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX >> 9);
>
> Shouldn't we fix the issue by capping to UINT_MAX >> 9 inside
> blk_queue_max_discard_sectors?  That way we'll prevent against having
> issues like this in any other driver as well.


Thanks Christoph, make sense to me, will rework it to this way.

Regards,
Jack

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2]brd: set max_discard_sectors properly
  2016-04-18  8:34   ` Jinpu Wang
@ 2016-04-18 13:55     ` Jinpu Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Jinpu Wang @ 2016-04-18 13:55 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, linux-kernel

On Mon, Apr 18, 2016 at 10:34 AM, Jinpu Wang
<jinpu.wang@profitbricks.com> wrote:
> On Sat, Apr 16, 2016 at 3:50 AM, Christoph Hellwig <hch@infradead.org> wrote:
>>> -     blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX);
>>> +     blk_queue_max_discard_sectors(brd->brd_queue, UINT_MAX >> 9);
>>
>> Shouldn't we fix the issue by capping to UINT_MAX >> 9 inside
>> blk_queue_max_discard_sectors?  That way we'll prevent against having
>> issues like this in any other driver as well.
>
>
> Thanks Christoph, make sense to me, will rework it to this way.
>
> Regards,
> Jack
It turns out, the real fix is here:

commit 5e4298be45e83ecdffaabb370eea9396889b07f1
Author: Bart Van Assche <bart.vanassche@sandisk.com>
Date: Tue Dec 15 16:38:22 2015 +0100
brd: Fix discard request processing
Avoid that discard requests with size => PAGE_SIZE fail with
-EIO. Refuse discard requests if the discard size is not a
multiple of the page size.
Fixes: 2dbe54957636 ("brd: Refuse improperly aligned discard requests")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Reviewed-by: Jan Kara <jack@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Robert Elliot <elliott@hp.com>
Cc: stable <stable@vger.kernel.org> # v4.4+
Signed-off-by: Jens Axboe <axboe@fb.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-18 13:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-15 14:24 [PATCHv2]brd: set max_discard_sectors properly Jinpu Wang
2016-04-16  1:50 ` Christoph Hellwig
2016-04-18  8:34   ` Jinpu Wang
2016-04-18 13:55     ` Jinpu Wang

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).