2016-04-15 14:24:45

by Jack Wang

[permalink] [raw]
Subject: [PATCHv2]brd: set max_discard_sectors properly

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.


Attachments:
0001-brd-set-max_discard_sectors-properly.patch (1.09 kB)

2016-04-16 01:50:24

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCHv2]brd: set max_discard_sectors properly

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

2016-04-18 08:34:41

by Jack Wang

[permalink] [raw]
Subject: Re: [PATCHv2]brd: set max_discard_sectors properly

On Sat, Apr 16, 2016 at 3:50 AM, Christoph Hellwig <[email protected]> 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

2016-04-18 13:56:11

by Jack Wang

[permalink] [raw]
Subject: Re: [PATCHv2]brd: set max_discard_sectors properly

On Mon, Apr 18, 2016 at 10:34 AM, Jinpu Wang
<[email protected]> wrote:
> On Sat, Apr 16, 2016 at 3:50 AM, Christoph Hellwig <[email protected]> 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 <[email protected]>
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 <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Robert Elliot <[email protected]>
Cc: stable <[email protected]> # v4.4+
Signed-off-by: Jens Axboe <[email protected]>