Skip to content

Commit 744889b

Browse files
Ming Leiaxboe
authored andcommitted
block: don't deal with discard limit in blkdev_issue_discard()
blk_queue_split() does respect this limit via bio splitting, so no need to do that in blkdev_issue_discard(), then we can align to normal bio submit(bio_add_page() & submit_bio()). More importantly, this patch fixes one issue introduced in a22c4d7 ("block: re-add discard_granularity and alignment checks"), in which zero discard bio may be generated in case of zero alignment. Fixes: a22c4d7 ("block: re-add discard_granularity and alignment checks") Cc: stable@vger.kernel.org Cc: Ming Lin <ming.l@ssi.samsung.com> Cc: Mike Snitzer <snitzer@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Xiao Ni <xni@redhat.com> Tested-by: Mariusz Dabrowski <mariusz.dabrowski@intel.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 7a7080b commit 744889b

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

block/blk-lib.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
2929
{
3030
struct request_queue *q = bdev_get_queue(bdev);
3131
struct bio *bio = *biop;
32-
unsigned int granularity;
3332
unsigned int op;
34-
int alignment;
3533
sector_t bs_mask;
3634

3735
if (!q)
@@ -54,38 +52,16 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
5452
if ((sector | nr_sects) & bs_mask)
5553
return -EINVAL;
5654

57-
/* Zero-sector (unknown) and one-sector granularities are the same. */
58-
granularity = max(q->limits.discard_granularity >> 9, 1U);
59-
alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
60-
6155
while (nr_sects) {
62-
unsigned int req_sects;
63-
sector_t end_sect, tmp;
56+
unsigned int req_sects = nr_sects;
57+
sector_t end_sect;
6458

65-
/*
66-
* Issue in chunks of the user defined max discard setting,
67-
* ensuring that bi_size doesn't overflow
68-
*/
69-
req_sects = min_t(sector_t, nr_sects,
70-
q->limits.max_discard_sectors);
7159
if (!req_sects)
7260
goto fail;
7361
if (req_sects > UINT_MAX >> 9)
7462
req_sects = UINT_MAX >> 9;
7563

76-
/*
77-
* If splitting a request, and the next starting sector would be
78-
* misaligned, stop the discard at the previous aligned sector.
79-
*/
8064
end_sect = sector + req_sects;
81-
tmp = end_sect;
82-
if (req_sects < nr_sects &&
83-
sector_div(tmp, granularity) != alignment) {
84-
end_sect = end_sect - alignment;
85-
sector_div(end_sect, granularity);
86-
end_sect = end_sect * granularity + alignment;
87-
req_sects = end_sect - sector;
88-
}
8965

9066
bio = next_bio(bio, 0, gfp_mask);
9167
bio->bi_iter.bi_sector = sector;

0 commit comments

Comments
 (0)